﻿Imports VN.INS.BL.BC
Imports System.Data
Imports System.Web
Imports System.IO

Partial Class Devida_MantenimientoPoaPestaña
    Inherits System.Web.UI.Page
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        btn_menos.Attributes.Add("onClick", "return confirm('Seguro que desea eliminar el registro?');")
        btn_menosFisico.Attributes.Add("onClick", "return confirm('Seguro que desea eliminar el registro?');")
        btn_menosfinan.Attributes.Add("onClick", "return confirm('Seguro que desea eliminar el registro?');")

        If (Not (Page.IsPostBack)) Then
            'Inicializamos variables a utilizar
            ViewState("dtcomponente") = New DataTable
            ViewState("dtfisico") = New DataTable()
            ViewState("dtfinanciero") = New DataTable()
            ViewState("VSAccion") = Request.QueryString("Accion").ToString
            ViewState("VScarga") = 1
            ViewState("VScargaf") = 1
            ViewState("VScargafn") = 1
            ViewState("VSind") = ""
            ViewState("VSindf") = ""
            ViewState("VSindfn") = ""
            ViewState("VStipod") = ""

            TabPanel6.Enabled = False 'Deshabilita el tab de las metas financieras

            'Carga de datos según sea la acción
            If ViewState("VSAccion") = "M" Then 'Edición... modificación 
                ViewState("VSPOA1") = Request.QueryString("Param").ToString
                ViewState("Version") = Request.QueryString("Version").ToString

                ADDCOLUM()
                ViewState("dtfinanciero").Rows.Clear()
                ViewState("dtfisico").Rows.Clear()
                ViewState("dtcomponente").Rows.Clear()
                LISTA_PPER()
                Lista_Especialista(ddl_pper.SelectedValue.ToString)
                LISTA_DEPARTAMENTO()
                LISTA_ESTADO()
                tipoProyectoActividad()
                Lista_Unidades()
                tipo_cambio()
                lista_ejecutor()
                modific_poaPrinc(ViewState("VSPOA1"))
                lista_ambito()
                CargarGrillaComponente(ViewState("VSPOA1"))
                CargarGrillafinanciero2(ViewState("VSPOA1"))
                lista_GENERICA()
                lista_ESPECIFICA2(ddl_generica.SelectedValue)
                LISTA_COMPONENTE(ViewState("VSPOA1"))
                Lista_tipo_transferencia()
                Lista_Tipo_Proyecto_Desarrollo()

                lbl_codigo.Text = "(" + ViewState("VSPOA1") + ")"
                label21.Text = "(" + ViewState("VSPOA1") + ") - " + ddl_ejec.SelectedItem.Text
                label82.Text = "(" + ViewState("VSPOA1") + ") - " + ddl_ejec.SelectedItem.Text
                label16.Text = "(" + ViewState("VSPOA1") + ") - " + ddl_ejec.SelectedItem.Text

                LIMPIARFISICO()
                LIMPIARFINANCIERA()
                chkb.Enabled = False
                Me.gv_fisico.EditIndex = -1
                Me.gv_fisico.DataSource = CargarGrillafisico4(ViewState("VSPOA1"))
                Me.gv_fisico.DataBind()

                Select Case ViewState("DIRECTIVA")
                    Case 2012, 2013
                        'Metas Fisicas                    
                        tbFisico.Visible = False            'tbFisico contiene los nuevos campos vigentes desde el 2014
                        'Metas Financieras                 
                        tbFinanc.Visible = False            'tbFisico contiene los nuevos campos vigentes desde el 2014
                        tdFinanciacion.Visible = False      'tbFisico contiene los nuevos campos vigentes desde el 2014

                        If Session("PERFIL") = "MO" Or Session("PERFIL") = "EP" Then
                            btn_guardPoa.Visible = False
                            Deshabilita_Controles_Pestanha_Cabecera_Poa()
                            Deshabilita_Controles_Pestanha_Componentes_Poa()
                            Deshabilita_Controles_Pestanha_Metas_Fisicas()
                            Deshabilita_Controles_Pestanha_Metas_Financieras()
                        End If

                    Case 2014

                        If Session("EstadoReprog") = "PROCESO REPROG." Then
                            If Session("PERFIL") = "MO" Or Session("PERFIL") = "EP" Then
                                btn_guardPoa.Visible = False
                                Deshabilita_Controles_Pestanha_Cabecera_Poa()
                                'Deshabilita_Controles_Pestanha_Componentes_Poa()
                                'Deshabilita_Controles_Pestanha_Metas_Fisicas()
                                'Deshabilita_Controles_Pestanha_Metas_Financieras()
                                If ddl_proy_act.SelectedValue = "2" Or ddl_proy_act.SelectedValue = "3" Then 'Sí es una Actividad o Acción Común
                                    Deshabilita_Pestanha_Componente_Poa() 'Deshabilitamos la pestaña Componente pues es una actividad...
                                End If

                            End If

                        Else
                            If Session("PERFIL") = "MO" Or Session("PERFIL") = "EP" Then
                                btn_guardPoa.Visible = False
                                Deshabilita_Controles_Pestanha_Cabecera_Poa()
                                Deshabilita_Controles_Pestanha_Componentes_Poa()
                                Deshabilita_Controles_Pestanha_Metas_Fisicas()
                                Deshabilita_Controles_Pestanha_Metas_Financieras()
                            End If
                        End If

                    Case Else 'Para el resto

                End Select

            Else                'Nuevo
                ViewState("Version") = 1
                chkb.Checked = True
                ADDCOLUM()
                LISTA_PPER()
                LISTA_DEPARTAMENTO()
                LISTA_PROVINCIA("1500")
                LISTA_DISTRITO("1501")
                LISTA_ESTADO()
                tipoProyectoActividad()
                Lista_Unidades()
                tipo_cambio()
                lista_ejecutor()
                lista_GENERICA()
                lista_ESPECIFICA2(ddl_generica.SelectedValue)
                LIMPIAR()
                lista_ambito()
                Lista_tipo_transferencia()
                dll_TipoTransferencia.SelectedValue = "all"
                'Lista_Tipo_Proyecto_Desarrollo()
                ViewState("VSdllsnip") = 0
                dll_TipoProyDES.SelectedValue = "all"
                LIMPIARFISICO()
                LIMPIARFINANCIERA()

                TabPanel2.Enabled = False 'Deshabilita el tab de los componentes
                TabPanel5.Enabled = False 'Deshabilita el tab de las metas físicas
                TabPanel6.Enabled = False 'Deshabilita el tab de las metas financieras

            End If
            If chkb.Checked = True Then
                ViewState("VSedit") = "I"
            End If
        End If
    End Sub

    Protected Sub chkb_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkb.CheckedChanged
        ' Si el checkbox está marcado es nuevo
        If chkb.Checked = True Then
            ViewState("VSedit") = "I"
        End If
        LIMPIAR()
    End Sub

    Protected Sub BLOQUEO()
        'Ocultamos los botones mas y menos
        btn_mas.Visible = False
        btn_masfinan.Visible = False
        btn_masfisico.Visible = False
        btn_menos.Visible = False
        btn_menosfinan.Visible = False
        btn_menosFisico.Visible = False
    End Sub

    Protected Sub Deshabilita_Controles_Pestanha_Cabecera_Poa()
        'Deshabilitamos los controles de la pestaña cabecera del Poa
        ddl_pper.Enabled = False
        ddl_ejec.Enabled = False
        txt_nom.Enabled = False
        txt_obj.Enabled = False
        ddl_producto.Enabled = False

        txt_DescMt1.Enabled = False
        txt_mt1.Enabled = False
        ddl_mt1.Enabled = False
        txt_invertido.Enabled = False

        txt_DescMt2.Enabled = False
        txt_mt2.Enabled = False
        ddl_mt2.Enabled = False
        txt_Monto_RO.Enabled = False

        txt_DescMt3.Enabled = False
        txt_mt3.Enabled = False
        ddl_mt3.Enabled = False

        txt_Monto_DT.Enabled = False
        ddl_monitor.Enabled = False
        ddl_depa.Enabled = False
        txt_invaño.Enabled = False
        ddl_especialista.Enabled = False
        ddl_provi.Enabled = False
        txt_MontoTransferido.Enabled = False
        ddl_proy_act.Enabled = False
        ddl_dist.Enabled = False
        txt_firma.Enabled = False
        ddl_ambito.Enabled = False
        txt_mesfirma.Enabled = False
        txt_fecha.Enabled = False
        ImgCalIni1.Enabled = False
        ddl_estado.Enabled = False
        txt_snip.Enabled = False
        txtdoc.Enabled = False
        txt_CoordX.Enabled = False
        ddl_tipocambio.Enabled = False
        chkb.Enabled = False
        txt_CoordY.Enabled = False
        dll_TipoTransferencia.Enabled = False
        dll_TipoProyDES.Enabled = False
        txtPeriodoIni.Enabled = False
        txtPeriodoFin.Enabled = False

        Label105.Enabled = False
        ddl_estado_ingreso.Enabled = False

        txt_Obs.Enabled = False

    End Sub

    Protected Sub Deshabilita_Pestanha_Componente_Poa()
        'Deshabilita la pestaña componentes del Poa
        TabContainer1.Tabs(1).Enabled = False
    End Sub

    Protected Sub Deshabilita_Controles_Pestanha_Componentes_Poa()
        'Deshabilitamos los controles de la pestaña componentes del Poa
        txt_componen.Enabled = False
        txt_peso.Enabled = False
        gv_componente.Enabled = False

        btn_mas.Visible = False
        btn_menos.Visible = False
        btn_guardComponente.Visible = False
    End Sub

    Protected Sub Deshabilita_Controles_Pestanha_Metas_Fisicas()
        'Deshabilitamos los controles de la pestaña de metas físicas del Poa
        ddl_compnt.Enabled = False
        txt_tarea.Enabled = False
        txtCOD.Enabled = False
        ddl_unidadfisica.Enabled = False
        txtpesoFisico.Enabled = False
        txtTotalFis.Enabled = False
        txtEjAcAntFis.Enabled = False
        gv_fisico.Enabled = False

        txt_1.Enabled = False
        txt_2.Enabled = False
        txt_3.Enabled = False
        txt_4.Enabled = False
        txt_5.Enabled = False
        txt_6.Enabled = False
        txt_7.Enabled = False
        txt_8.Enabled = False
        txt_9.Enabled = False
        txt_10.Enabled = False
        txt_11.Enabled = False
        txt_12.Enabled = False

        btn_masfisico.Visible = False
        btn_menosFisico.Visible = False
        btn_guardFisico.Visible = False
    End Sub

    Protected Sub Deshabilita_Controles_Pestanha_Metas_Financieras()
        'Deshabilitamos los controles de la pestaña de metas físicas del Poa
        ddl_generica.Enabled = False
        ddl_especifica.Enabled = False
        txtMetaTotalFin.Enabled = False
        txtMetaEjecacAntFin.Enabled = False
        txtEjecutora.Enabled = False
        txtDevida.Enabled = False
        txtOtros.Enabled = False
        gv_actfinan.Enabled = False

        txt_1f.Enabled = False
        txt_2f.Enabled = False
        txt_3f.Enabled = False
        txt_4f.Enabled = False
        txt_5f.Enabled = False
        txt_6f.Enabled = False
        txt_7f.Enabled = False
        txt_8f.Enabled = False
        txt_9f.Enabled = False
        txt_10f.Enabled = False
        txt_11f.Enabled = False
        txt_12f.Enabled = False

        btn_masfinan.Visible = False
        btn_menosfinan.Visible = False
        btn_guardFinanciero.Visible = False
    End Sub

    Protected Sub ADDCOLUM()
        'Cargamos columnas iniciales de tablas componente, fisico y financiero
        If ViewState("VScarga") = 1 And ViewState("dtcomponente").Columns.Count = 0 Then
            ViewState("dtcomponente").Columns.Add("poa")
            ViewState("dtcomponente").Columns.Add("componente")
            ViewState("dtcomponente").Columns.Add("version")
            ViewState("dtcomponente").Columns.Add("codigo")
            ViewState("dtcomponente").Columns.Add("PESO_COMPONENTE")
            ViewState("VScarga") = 0
        End If
        If ViewState("VScargaf") = 1 And ViewState("dtfisico").Columns.Count = 0 Then
            ViewState("dtfisico").Columns.Add("unidad")
            ViewState("dtfisico").Columns.Add("unidaddes")
            ViewState("dtfisico").Columns.Add("Componente")
            ViewState("dtfisico").Columns.Add("ComponenteDes")
            ViewState("dtfisico").Columns.Add("Tarea")
            ViewState("dtfisico").Columns.Add("meta_01")
            ViewState("dtfisico").Columns.Add("meta_02")
            ViewState("dtfisico").Columns.Add("meta_03")
            ViewState("dtfisico").Columns.Add("meta_04")
            ViewState("dtfisico").Columns.Add("meta_05")
            ViewState("dtfisico").Columns.Add("meta_06")
            ViewState("dtfisico").Columns.Add("meta_07")
            ViewState("dtfisico").Columns.Add("meta_08")
            ViewState("dtfisico").Columns.Add("meta_09")
            ViewState("dtfisico").Columns.Add("meta_10")
            ViewState("dtfisico").Columns.Add("meta_11")
            ViewState("dtfisico").Columns.Add("meta_12")
            ViewState("dtfisico").Columns.Add("meta_anual")
            ViewState("dtfisico").Columns.Add("version")
            ViewState("dtfisico").Columns.Add("ID_POA_ACTIVIDAD_FISICA")
            ViewState("dtfisico").Columns.Add("META_TOTAL")
            ViewState("dtfisico").Columns.Add("META_EJEC_ACUM_ANT")
            ViewState("VScargaf") = 0
        End If
        If ViewState("VScargafn") = 1 And ViewState("dtfinanciero").Columns.Count = 0 Then
            ViewState("dtfinanciero").Columns.Add("ESPECIFICA_GASTO")
            ViewState("dtfinanciero").Columns.Add("ESPECIFICA_GASTODES")
            ViewState("dtfinanciero").Columns.Add("GENERICA_GASTO")
            ViewState("dtfinanciero").Columns.Add("GENERICA_GASTODES")
            ViewState("dtfinanciero").Columns.Add("meta_01")
            ViewState("dtfinanciero").Columns.Add("meta_02")
            ViewState("dtfinanciero").Columns.Add("meta_03")
            ViewState("dtfinanciero").Columns.Add("meta_04")
            ViewState("dtfinanciero").Columns.Add("meta_05")
            ViewState("dtfinanciero").Columns.Add("meta_06")
            ViewState("dtfinanciero").Columns.Add("meta_07")
            ViewState("dtfinanciero").Columns.Add("meta_08")
            ViewState("dtfinanciero").Columns.Add("meta_09")
            ViewState("dtfinanciero").Columns.Add("meta_10")
            ViewState("dtfinanciero").Columns.Add("meta_11")
            ViewState("dtfinanciero").Columns.Add("meta_12")
            ViewState("dtfinanciero").Columns.Add("version")
            ViewState("dtfinanciero").Columns.Add("meta_anual")
            ViewState("dtfinanciero").Columns.Add("ID_POA_ACTIVIDAD_FINANCIERA")
            ViewState("dtfinanciero").Columns.Add("META_TOTAL")
            ViewState("dtfinanciero").Columns.Add("META_EJEC_ACUM_ANT")
            ViewState("dtfinanciero").Columns.Add("EJECUTORA")
            ViewState("dtfinanciero").Columns.Add("DEVIDA")
            ViewState("dtfinanciero").Columns.Add("OTROS")
            ViewState("VScargafn") = 0
        End If
    End Sub

    Protected Sub ddl_generica_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_generica.SelectedIndexChanged
        'cargamos combo especifico, segun la generica seleccionada
        lista_ESPECIFICA2(ddl_generica.SelectedValue.ToString)
    End Sub

    Private Function CuentaCaracter(ByVal cadena As String, ByVal caracter As Char) As Integer
        'contamos el numero de veces que un caracter se repite
        Dim contador As Integer
        contador = 0
        For Each c As Char In cadena.ToCharArray
            If c.ToString.Equals(caracter.ToString) Then
                contador = contador + 1
            End If
        Next
        Return contador
    End Function

    '================================================= REGIONES ===========================================================

#Region "PRINCIPAL"

    Protected Sub LIMPIAR()
        'limpiamos controles de tap principal
        txt_nom.Text = ""
        txt_fecha.Text = ""
        txt_firma.Text = ""
        txt_mesfirma.Text = ""
        txt_mt1.Text = ""
        txt_mt2.Text = ""
        txt_mt3.Text = ""
        txt_snip.Text = ""
        txt_obj.Text = ""

        txtPeriodoIni.Text = ""
        txtPeriodoFin.Text = ""

        Lista_Monitoreador(ddl_pper.SelectedValue.ToString)
        Lista_Especialista(ddl_pper.SelectedValue.ToString)
        LISTA_DEPARTAMENTO()
        LISTA_PPER()
        LISTA_ESTADO()
        tipoProyectoActividad()

        txt_invertido.Text = ""

        'txt_invaño.Text = ""
        'txt_MontoTransferido.Text = ""

        ddl_depa.SelectedValue = "all"
        ddl_provi.SelectedValue = "all"
        ddl_dist.SelectedValue = "all"
        ddl_ambito.SelectedValue = "all"

        ddl_especialista.SelectedValue = "all"
        ddl_estado.SelectedValue = "all"
        ddl_monitor.SelectedValue = "all"

        ddl_mt1.SelectedValue = ""
        ddl_mt2.SelectedValue = ""
        ddl_mt3.SelectedValue = ""
        ddl_pper.SelectedValue = "all"

        ddl_producto.SelectedValue = "all"
        ddl_proy_act.SelectedValue = "all"
        dll_TipoProyDES.SelectedValue = "all"

        ddl_tipocambio.SelectedValue = "all"
        ddl_ejec.SelectedValue = "all"
        ddl_unidadfisica.SelectedValue = ""
        ddl_generica.SelectedValue = "all"

        ddl_monitor.SelectedValue = "all"
    End Sub

    'By Tigrito
    Private Function Valida_metas() As Boolean
        Dim boo_cumple As Boolean = True
        If Not (txt_DescMt1.Text.Trim = "") Then
            If txt_mt1.Text.Trim = "" Or ddl_mt1.SelectedValue = "" Then
                boo_cumple = False
            End If
        End If
        If Not (txt_DescMt2.Text.Trim = "") Then
            If txt_mt2.Text.Trim = "" Or ddl_mt2.SelectedValue = "" Then
                boo_cumple = False
            End If
        End If
        If Not (txt_DescMt3.Text.Trim = "") Then
            If txt_mt3.Text.Trim = "" Or ddl_mt3.SelectedValue = "" Then
                boo_cumple = False
            End If
        End If
        Return boo_cumple
    End Function

    Protected Sub btn_guardPoa_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_guardPoa.Click

        'Validamos si faltan ingresar datos obligatorios
        If ddl_pper.SelectedValue = "all" Or txt_nom.Text = "" Or ddl_monitor.SelectedValue = "all" Or ddl_depa.SelectedValue = "all" Or ddl_estado.SelectedValue = "all" Or ddl_ejec.SelectedValue = "all" Or ddl_especialista.SelectedValue = "all" Or ddl_proy_act.SelectedValue = "all" Or dll_TipoTransferencia.SelectedValue = "all Then" Or txt_invertido.Text = "" Or txt_firma.Text = "" Or ddl_ambito.SelectedValue = "all" Or txtPeriodoIni.Text.Trim = "" Then
            'Si faltan datos
            alerta.Mostrar_Alerta("Aviso", "Falta llenar el campo : " & IIf(ddl_pper.SelectedValue = "all", " - PPER", "") & IIf(txt_nom.Text = "", " - Nombre", "") & IIf(ddl_monitor.SelectedValue = "all", " - Monitoreador", "") & IIf(ddl_depa.SelectedValue = "all", " - Departamento", "") & IIf(ddl_estado.SelectedValue = "all", " - Estado", "") & IIf(ddl_ejec.SelectedValue = "all", " - Ejecutor", "") & IIf(ddl_especialista.SelectedValue = "all", " - Especialista", "") & IIf(ddl_proy_act.SelectedValue = "all", " - Proyecyo/Actividad", "") & IIf(txt_invertido.Text = "", " - Monto Invertido", "") & IIf(txt_firma.Text = "", " - Monto Total", "") & IIf(ddl_ambito.SelectedValue = "all", " - Ambito ", "") & IIf(dll_TipoProyDES.SelectedValue = "all" And ddl_proy_act.SelectedValue = "1", " - tipoProyecto ", "") & IIf(txtPeriodoIni.Text.Trim = "", " - Periodo Inicio", "") & IIf(ddl_estado_ingreso.SelectedValue = "all", " - Estado Ingreso Poa ", ""))

        Else

            If ViewState("VSdllsnip") = 1 And dll_TipoProyDES.SelectedValue = "all" Then
                alerta.Mostrar_Alerta("Aviso", "Debe elegir Tipo de proyecto.")
            ElseIf ViewState("VSdllsnip") <> 1 And dll_TipoProyDES.SelectedValue <> "all" Then
                alerta.Mostrar_Alerta("Aviso", "No debe elegir Tipo de proyecto.")
            Else
                'Validamos las metas        'By Tigrito
                If Valida_metas() = False Then
                    alerta.Mostrar_Alerta("Aviso", "Debe completar datos de meta")
                    Exit Sub
                End If
                'Validamos SNIP             'By Tigrito
                If ddl_proy_act.SelectedValue = "1" Then
                    If txt_snip.Text.Trim = "" Then
                        alerta.Mostrar_Alerta("Aviso", "Debe ingresar el código SNIP")
                        Exit Sub
                    End If
                End If
                'No faltan datos
                Dim strUbigeo As String = ""

                If ddl_depa.SelectedValue.ToString = "all" Then
                    alerta.Mostrar_Alerta("Aviso", "Debe seleccionar una región")
                Else
                    strUbigeo = ddl_depa.SelectedValue.ToString
                    If ddl_dist.SelectedValue <> "all" Then
                        strUbigeo = ddl_dist.SelectedValue.ToString
                    Else
                        If ddl_provi.SelectedValue <> "all" Then
                            strUbigeo = ddl_provi.SelectedValue.ToString
                        Else
                            strUbigeo = ddl_depa.SelectedValue.ToString
                        End If
                    End If
                End If

                'Datos de metas

                If ViewState("VSAccion") = "M" Then ' Edición (Modificación)
                    Dim strVERS As Integer
                    strVERS = ViewState("Version")

                    editar_poa_principal(ddl_tipocambio.SelectedValue.ToString, ddl_ejec.SelectedValue.ToString, txtdoc.Text, strVERS,
                                         ViewState("VSPOA1"), Server.HtmlDecode(txt_nom.Text), Server.HtmlDecode(txt_obj.Text),
                                         txt_DescMt1.Text, (IIf(txt_mt1.Text = "", 0, txt_mt1.Text)), ddl_mt1.SelectedValue.ToString,
                                         txt_DescMt2.Text, (IIf(txt_mt2.Text = "", 0, txt_mt2.Text)), ddl_mt2.SelectedValue.ToString,
                                         txt_DescMt3.Text, (IIf(txt_mt3.Text = "", 0, txt_mt3.Text)), ddl_mt3.SelectedValue.ToString,
                                         (IIf(txt_invertido.Text = "", 0, txt_invertido.Text)),
                                         (IIf(txt_invaño.Text = "", 0, txt_invaño.Text)), txt_firma.Text, ddl_monitor.SelectedValue.ToString,
                                         ddl_especialista.SelectedValue.ToString, txt_mesfirma.Text, strUbigeo, ddl_proy_act.SelectedValue.ToString,
                                         txt_snip.Text, txt_fecha.Text, "", ddl_ambito.SelectedValue.ToString, ddl_estado.SelectedValue.ToString,
                                         ddl_pper.SelectedValue.ToString, ddl_producto.SelectedValue.ToString, txt_MontoTransferido.Text,
                                         dll_TipoTransferencia.SelectedValue.ToString, dll_TipoProyDES.SelectedValue.ToString,
                                         (IIf(txt_Monto_RO.Text = "", 0, txt_Monto_RO.Text)), (IIf(txt_Monto_DT.Text = "", 0, txt_Monto_DT.Text)), ddl_estado_ingreso.SelectedValue.ToString)
                    alerta.Mostrar_Alerta("Aviso", "Datos Actualizados Correctamente")

                ElseIf ViewState("VSedit") = "I" Then ' Inserción
                    Dim objgenj As GeneralBC
                    Dim strVERS As Integer
                    strVERS = ViewState("Version")
                    objgenj = New GeneralBC
                    ViewState("VSstrPOA") = objgenj.GenerarCodigo("POA", "POA", "POA-")

                    'Se insertan los datos del POA
                    insertar_poa(ddl_tipocambio.SelectedValue.ToString, ddl_ejec.SelectedValue.ToString, txtdoc.Text, strVERS,
                                 ViewState("VSstrPOA"), Server.HtmlDecode(txt_nom.Text), Server.HtmlDecode(txt_obj.Text),
                                 txt_DescMt1.Text, (IIf(txt_mt1.Text = "", 0, txt_mt1.Text)), ddl_mt1.SelectedValue.ToString,
                                 txt_DescMt2.Text, (IIf(txt_mt2.Text = "", 0, txt_mt2.Text)), ddl_mt2.SelectedValue.ToString,
                                 txt_DescMt3.Text, (IIf(txt_mt3.Text = "", 0, txt_mt3.Text)), ddl_mt3.SelectedValue.ToString,
                                 (IIf(txt_invertido.Text = "", 0, txt_invertido.Text)), (IIf(txt_invaño.Text = "", 0, txt_invaño.Text)),
                                 txt_firma.Text, ddl_monitor.SelectedValue.ToString,
                                 ddl_especialista.SelectedValue.ToString, txt_mesfirma.Text, strUbigeo, ddl_proy_act.SelectedValue.ToString,
                                 txt_snip.Text, txt_fecha.Text, "", ddl_ambito.SelectedValue.ToString,
                                 ddl_estado.SelectedValue.ToString, ddl_pper.SelectedValue.ToString, ddl_producto.SelectedValue.ToString,
                                 (IIf(txt_MontoTransferido.Text = "", 0, txt_MontoTransferido.Text)), dll_TipoTransferencia.SelectedValue.ToString,
                                 dll_TipoProyDES.SelectedValue.ToString, (IIf(txt_Monto_RO.Text = "", 0, txt_Monto_RO.Text)),
                                 (IIf(txt_Monto_DT.Text = "", 0, txt_Monto_DT.Text)), ddl_estado_ingreso.SelectedValue.ToString)

                    TabPanel2.Enabled = True 'Se rehabilita el tab de los componentes
                    TabPanel5.Enabled = True 'Se rehabilita el tab de las metas físicas
                    TabPanel6.Enabled = True 'Se rehabilita el tab de las metas financieras

                    alerta.Mostrar_Alerta("Aviso", "Datos Guardados Correctamente")
                    ViewState("VSAccion") = "M"
                    ViewState("VSPOA1") = ViewState("VSstrPOA")
                    ViewState("VSAccion1") = "N"
                End If
            End If
        End If
    End Sub

    Protected Sub btnsalir_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnsalir.Click
        'salir
        Response.Redirect("MantenimientoPoa.aspx")
    End Sub

    'edicion de poa
    Public Sub editar_poa_principal(ByVal tipCamb As String, ByVal ejec As String, ByVal doc As String, ByVal VERS As Integer, ByVal POA1 As String,
                                    ByVal nomb As String, ByVal obj As String,
                                    ByVal Desc_mt1 As String, ByVal mt1 As String, ByVal umt1 As String,
                                    ByVal Desc_mt2 As String, ByVal mt2 As String, ByVal umt2 As String,
                                    ByVal Desc_mt3 As String, ByVal mt3 As String, ByVal umt3 As String,
                                    ByVal monto As Decimal, ByVal montoaño As Decimal,
                                    ByVal añofirm As String, ByVal monitoreador As String, ByVal espec As String, ByVal mesfirm As String,
                                    ByVal dpto As String, ByVal tipodoc As String, ByVal snip As String, ByVal fviabilidad As String,
                                    ByVal convenio As String, ByVal ambit As String, ByVal estado As String, ByVal pper As String,
                                    ByVal produc As String, ByVal MontTrans As String, ByRef TipoAsig As String, ByVal TipoProyDes As String,
                                    ByVal montoRO As String, ByVal montoDT As String, ByVal EstadoIngreso As String)
        If umt1 = "" Then
            umt1 = ""
        End If
        If umt2 = "" Then
            umt2 = ""
        End If
        If umt3 = "" Then
            umt3 = ""
        End If
        If monitoreador = "all" Then
            monitoreador = ""
        End If
        If espec = "all" Then
            espec = ""
        End If
        If estado = "all" Then
            estado = ""
        End If
        If pper = "all" Then
            pper = ""
        End If
        If produc = "all" Then
            produc = ""
        End If
        If tipodoc = "all" Then
            tipodoc = ""
        End If
        If convenio = "all" Then
            convenio = ""
        End If
        If ejec = "all" Then
            ejec = ""
        End If
        If tipCamb = "all" Then
            tipCamb = ""
        End If
        If dpto = "all" Then
            dpto = ""
        End If
        If TipoAsig = "all" Then
            TipoAsig = ""
        End If
        If TipoProyDes = "all" Then
            TipoProyDes = ""
        End If
        If EstadoIngreso = "all" Then
            EstadoIngreso = ""
        End If

        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Try
            objMantenimientoPoaBC = New MantenimientoPoaBC
            objMantenimientoPoaBC.editar_poa_principal(tipCamb, ejec, doc, VERS, POA1, nomb.ToUpper, obj, Desc_mt1, mt1, umt1, Desc_mt2, mt2, umt2, Desc_mt3, mt3, umt3, monto,
                                                       montoaño, añofirm, monitoreador, espec, mesfirm, dpto, tipodoc, snip, fviabilidad, convenio,
                                                       ambit, estado, pper, produc, IIf(MontTrans = "", 0, MontTrans), TipoAsig, TipoProyDes,
                                                       txt_CoordX.Text, txt_CoordY.Text, txt_Obs.Text, txtPeriodoIni.Text, txtPeriodoFin.Text,
                                                        montoRO, montoDT, EstadoIngreso)

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub Lista_Monitoreador(ByVal strCodPPER As String)

        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = New DataTable
        ObjData = ObjMantenimientoPoaBC.Lista_Monitoreador(strCodPPER)

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("NOMBRES") = "--Seleccione--"
        drestadorow("Persona") = "all"

        'ObjData.Rows.Add(drestadorow)
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_monitor.DataSource = ObjData
        ddl_monitor.DataTextField = "NOMBRES"
        ddl_monitor.DataValueField = "Persona"
        ddl_monitor.DataBind()

    End Sub

    Public Sub tipo_cambio()
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = ObjMantenimientoPoaBC.tipo_cambio()

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("DESCRIPCION") = "--Seleccione--"
        drestadorow("CODIGO") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_tipocambio.DataSource = ObjData
        ddl_tipocambio.DataTextField = "DESCRIPCION"
        ddl_tipocambio.DataValueField = "CODIGO"
        ddl_tipocambio.DataBind()
    End Sub

    Public Sub lista_ejecutor()
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = ObjMantenimientoPoaBC.lista_ejecutor()

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("DESCRIPCION") = "--Seleccione--"
        drestadorow("EJECUTOR") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_ejec.DataSource = ObjData
        ddl_ejec.DataTextField = "DESCRIPCION"
        ddl_ejec.DataValueField = "EJECUTOR"
        ddl_ejec.DataBind()
    End Sub

    Public Sub lista_ambito()
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = ObjMantenimientoPoaBC.lista_ambito()

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("DESCRIPCION") = "--Seleccione--"
        drestadorow("CODIGO") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_ambito.DataSource = ObjData
        ddl_ambito.DataTextField = "DESCRIPCION"
        ddl_ambito.DataValueField = "CODIGO"
        ddl_ambito.DataBind()
    End Sub

    Public Sub Lista_Unidades()
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = New DataTable
        ObjData = ObjMantenimientoPoaBC.Lista_Unidades()

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("DESCRIPCION") = "--Seleccione--"
        drestadorow("UNIDAD") = ""
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_mt1.DataSource = ObjData
        ddl_mt1.DataTextField = "DESCRIPCION"
        ddl_mt1.DataValueField = "UNIDAD"
        ddl_mt1.DataBind()

        ddl_mt2.DataSource = ObjData
        ddl_mt2.DataTextField = "DESCRIPCION"
        ddl_mt2.DataValueField = "UNIDAD"
        ddl_mt2.DataBind()

        ddl_mt3.DataSource = ObjData
        ddl_mt3.DataTextField = "DESCRIPCION"
        ddl_mt3.DataValueField = "UNIDAD"
        ddl_mt3.DataBind()

        ddl_unidadfisica.DataSource = ObjData
        ddl_unidadfisica.DataTextField = "DESCRIPCION"
        ddl_unidadfisica.DataValueField = "UNIDAD"
        ddl_unidadfisica.DataBind()
    End Sub

    Public Sub LISTA_PPER()
        Dim objMONITOREOBC As MONITOREOBC
        Dim ObjData As DataTable
        objMONITOREOBC = New MONITOREOBC
        ObjData = New DataTable
        ObjData = objMONITOREOBC.ppermonitor()
        Dim drpperrow As DataRow = ObjData.NewRow()
        drpperrow("ABREVIATURA") = "--Seleccione--"
        drpperrow("PPER") = "all"
        ObjData.Rows.InsertAt(drpperrow, 0)
        ddl_pper.DataSource = ObjData
        ddl_pper.DataTextField = "ABREVIATURA"
        ddl_pper.DataValueField = "PPER"
        ddl_pper.DataBind()
    End Sub

    Public Sub ListaMonitoreador(ByVal strCodPPER As String)
        Dim objusuario As UsuarioBC
        Dim objData As DataTable

        objusuario = New UsuarioBC
        objData = New DataTable
        objData = objusuario.ListaMonitoreadorMantPoa(strCodPPER)

        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("NOMBRE") = "--Seleccione--"
        drusuariorow("PERSONA") = "all"
        objData.Rows.InsertAt(drusuariorow, 0)
        ddl_monitor.DataSource = objData
        ddl_monitor.DataTextField = "NOMBRE"
        ddl_monitor.DataValueField = "PERSONA"
        ddl_monitor.DataBind()
    End Sub

    Public Sub Lista_Especialista(ByVal strCodPPER As String)
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = New DataTable
        ObjData = ObjMantenimientoPoaBC.ListaEspecialistaMantPoa(strCodPPER)

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("NOMBRES") = "--Seleccione--"
        drestadorow("Persona") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_especialista.DataSource = ObjData
        ddl_especialista.DataTextField = "NOMBRES"
        ddl_especialista.DataValueField = "Persona"
        ddl_especialista.DataBind()
    End Sub

    Public Sub LISTA_DEPARTAMENTO()
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = New DataTable
        ObjData = ObjMantenimientoPoaBC.lista_departamento()

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("NOMBRE") = "--Seleccione--"
        drestadorow("ubigeo") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)

        'Cargando los campos del dropdownlist
        ddl_depa.DataSource = ObjData
        ddl_depa.DataTextField = "NOMBRE"
        ddl_depa.DataValueField = "ubigeo"
        ddl_depa.DataBind()
        ddl_depa.SelectedValue = "all"
    End Sub

    Public Sub LISTA_PROVINCIA(ByVal strUbigeo As String)
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = New DataTable
        ObjData = ObjMantenimientoPoaBC.lista_provincia(strUbigeo)

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("NOMBRE") = "--Seleccione--"
        drestadorow("ubigeo") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)

        'Cargando los campos del dropdownlist
        ddl_provi.DataSource = ObjData
        ddl_provi.DataTextField = "NOMBRE"
        ddl_provi.DataValueField = "ubigeo"
        ddl_provi.DataBind()
        ddl_provi.SelectedValue = "all"
    End Sub

    Public Sub LISTA_DISTRITO(ByVal strUbigeo As String)
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = New DataTable
        ObjData = ObjMantenimientoPoaBC.lista_distrito(strUbigeo)

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("NOMBRE") = "--Seleccione--"
        drestadorow("ubigeo") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_dist.DataSource = ObjData
        ddl_dist.DataTextField = "NOMBRE"
        ddl_dist.DataValueField = "ubigeo"
        ddl_dist.DataBind()
        ddl_dist.SelectedValue = "all"
    End Sub

    Public Sub Lista_tipo_transferencia()
        Dim objLTT As MantenimientoPoaBC
        Dim objdt As DataTable
        objLTT = New MantenimientoPoaBC
        objdt = New DataTable
        objdt = objLTT.TipoTransferencia()

        Dim drtipotransferencia As DataRow = objdt.NewRow()
        drtipotransferencia("DESCRIPCION") = "--Seleccione--"
        drtipotransferencia("CODIGO") = "all"
        objdt.Rows.InsertAt(drtipotransferencia, 0)
        dll_TipoTransferencia.DataSource = objdt
        dll_TipoTransferencia.DataTextField = "DESCRIPCION"
        dll_TipoTransferencia.DataValueField = "CODIGO"
        dll_TipoTransferencia.DataBind()
    End Sub

    Protected Sub ddl_pper_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_pper.SelectedIndexChanged
        'lista_producto(ddl_pper.SelectedValue.ToString)
        ListaMonitoreador(ddl_pper.SelectedValue.ToString)
        Lista_Especialista(ddl_pper.SelectedValue.ToString)
    End Sub

    Protected Sub ddl_proy_act_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_proy_act.SelectedIndexChanged
        ViewState("VSdllsnip") = ddl_proy_act.SelectedValue.ToString
        'If ddl_proy_act.SelectedValue.ToString <> "1" Then
        '    dll_TipoProyDES.SelectedValue = "all"
        'End If

        Select Case ddl_proy_act.SelectedValue.ToString
            Case "1" 'Proyecto
                lista_producto_vacia()
                Lista_Tipo_Proyecto_Desarrollo()
            Case "2" 'Actividad
                lista_producto(ddl_pper.SelectedValue.ToString)
                Lista_Tipo_Proyecto_Desarrollo_Vacia()
            Case "3" 'Acción común
                lista_producto_vacia()
                Lista_Tipo_Proyecto_Desarrollo_Vacia()

            Case Else

        End Select

    End Sub

    Public Sub tipoProyectoActividad()
        Dim objMONITOREOBC As MONITOREOBC = New MONITOREOBC
        Dim objData As DataTable

        objData = objMONITOREOBC.tipoProyectoActividad()
        Dim drestadorow As DataRow = objData.NewRow()
        drestadorow("DESCRIPCION") = "--Seleccione--"
        drestadorow("tipo_proyecto_actividad") = "all"
        objData.Rows.InsertAt(drestadorow, 0)
        ddl_proy_act.DataSource = objData
        ddl_proy_act.DataTextField = "DESCRIPCION"
        ddl_proy_act.DataValueField = "tipo_proyecto_actividad"
        ddl_proy_act.DataBind()
    End Sub

    Public Sub lista_producto(ByVal ppr As String)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC

        'Carga los productos segun el pper seleccionado
        ObjData = objMantenimientoPoaBC.lista_producto(ppr)

        Dim drpperrow As DataRow = ObjData.NewRow()
        drpperrow("descripcion") = "--Seleccione--"
        drpperrow("producto") = "all"
        ObjData.Rows.InsertAt(drpperrow, 0)

        ddl_producto.DataSource = ObjData
        ddl_producto.DataTextField = "descripcion"
        ddl_producto.DataValueField = "producto"
        ddl_producto.DataBind()
    End Sub

    Public Sub lista_producto_vacia()
        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC

        'Carga los productos segun el pper seleccionado
        ObjData = objMantenimientoPoaBC.lista_producto("XYZ")

        Dim drpperrow As DataRow = ObjData.NewRow()
        drpperrow("descripcion") = "--Seleccione--"
        drpperrow("producto") = "all"
        ObjData.Rows.InsertAt(drpperrow, 0)

        ddl_producto.DataSource = ObjData
        ddl_producto.DataTextField = "descripcion"
        ddl_producto.DataValueField = "producto"
        ddl_producto.DataBind()
    End Sub

    Public Sub Lista_Tipo_Proyecto_Desarrollo()
        Dim objLTPD As MantenimientoPoaBC
        Dim objdt As DataTable
        objLTPD = New MantenimientoPoaBC
        objdt = New DataTable
        objdt = objLTPD.TipoProyectoDES()

        Dim drtipoproyectodes As DataRow = objdt.NewRow()
        drtipoproyectodes("DESCRIPCION") = "--Seleccione--"
        drtipoproyectodes("CODIGO") = "all"
        objdt.Rows.InsertAt(drtipoproyectodes, 0)
        dll_TipoProyDES.DataSource = objdt
        dll_TipoProyDES.DataTextField = "DESCRIPCION"
        dll_TipoProyDES.DataValueField = "CODIGO"
        dll_TipoProyDES.DataBind()
    End Sub

    Public Sub Lista_Tipo_Proyecto_Desarrollo_Vacia()

        dll_TipoProyDES.Items.Clear()

        Dim HashTable1 As New System.Collections.Hashtable()

        HashTable1("all") = "--Seleccione--"
        'HashTable1("PS") = "Paris"
        'HashTable1("BR") = "Brasilia"

        For Each Item In HashTable1
            Dim newListItem As New ListItem()
            newListItem.Text = Item.Value
            newListItem.Value = Item.Key
            dll_TipoProyDES.Items.Add(newListItem)
        Next

    End Sub

    Public Sub LISTA_ESTADO()
        Dim ObjMantenimientoUsuarioBC As GeneralBC
        Dim ObjData As DataTable
        ObjMantenimientoUsuarioBC = New GeneralBC
        ObjData = New DataTable
        ObjData = ObjMantenimientoUsuarioBC.ListaTablaGeneral("ESTADO_POA")

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("DESCRIPCION") = "--Seleccione--"
        drestadorow("CODIGO") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_estado.DataSource = ObjData
        ddl_estado.DataTextField = "DESCRIPCION"
        ddl_estado.DataValueField = "CODIGO"
        ddl_estado.DataBind()
    End Sub

    'Insertar poa
    Public Sub insertar_poa(ByVal tipCamb As String, ByVal ejec As String, ByVal doc As String, ByVal VERS As Integer, ByVal POA1 As String,
                            ByVal nomb As String, ByVal obj As String,
                            ByVal Desc_mt1 As String, ByVal mt1 As String, ByVal umt1 As String,
                            ByVal Desc_mt2 As String, ByVal mt2 As String, ByVal umt2 As String,
                            ByVal Desc_mt3 As String, ByVal mt3 As String, ByVal umt3 As String,
                            ByVal monto As Decimal, ByVal montoaño As Decimal,
                            ByVal añofirm As String, ByVal monitoreador As String, ByVal espec As String, ByVal mesfirm As String, ByVal dpto As String,
                            ByVal tipodoc As String, ByVal snip As String, ByVal fviabilidad As String, ByVal convenio As String, ByVal ambit As String,
                            ByVal estado As String, ByVal pper As String, ByVal produc As String, ByVal MontTrans As Decimal, ByRef TipoAsig As String,
                            ByVal TipoProyDes As String, ByVal montoRO As String, ByVal montoDT As String, ByVal EstadoIngreso As String)
        If umt1 = "" Then
            umt1 = ""
        End If
        If umt2 = "" Then
            umt2 = ""
        End If
        If umt3 = "" Then
            umt3 = ""
        End If
        If monitoreador = "all" Then
            monitoreador = ""
        End If
        If espec = "all" Then
            espec = ""
        End If
        If estado = "all" Then
            estado = ""
        End If
        If pper = "all" Then
            pper = ""
        End If
        If produc = "all" Then
            produc = ""
        End If
        If tipodoc = "all" Then
            tipodoc = ""
        End If
        If convenio = "all" Then
            convenio = ""
        End If
        If ejec = "all" Then
            ejec = ""
        End If
        If tipCamb = "all" Then
            tipCamb = ""
        End If
        If dpto = "all" Then
            dpto = ""
        End If
        If TipoAsig = "all" Then
            TipoAsig = ""
        End If
        If TipoProyDes = "all" Then
            TipoProyDes = ""
        End If
        If EstadoIngreso = "all" Then
            EstadoIngreso = ""
        End If

        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Try
            objMantenimientoPoaBC = New MantenimientoPoaBC
            objMantenimientoPoaBC.insertar_poa(tipCamb, ejec, doc, VERS, POA1, nomb.ToUpper, obj, Desc_mt1, mt1, umt1, Desc_mt2, mt2, umt2, Desc_mt3, mt3, umt3, monto, montoaño,
                                               añofirm, monitoreador, espec, mesfirm, dpto, tipodoc, snip, fviabilidad, convenio, ambit, estado, pper,
                                               produc, MontTrans, TipoAsig, TipoProyDes, txt_CoordX.Text, txt_CoordY.Text, txt_Obs.Text,
                                               txtPeriodoIni.Text, txtPeriodoFin.Text, montoRO, montoDT, EstadoIngreso)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub modific_poaPrinc(ByVal POA As String)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC
        'Carga el tab principal 
        ObjData = objMantenimientoPoaBC.modific_poaPrinc(POA)
        ViewState("DIRECTIVA") = ObjData.Rows(0)("DIRECTIVA")

        If IsDBNull(ObjData.Rows(0).Item("NOMBRE")) Then
            txt_nom.Text = ""
        Else
            txt_nom.Text = ObjData.Rows(0).Item("NOMBRE")
        End If
        If IsDBNull(ObjData.Rows(0).Item("UBIGEO")) Then
            ddl_depa.SelectedValue = "all"
            ddl_provi.SelectedValue = "all"
            ddl_dist.SelectedValue = "all"
        Else
            Dim strUbigeo As String = ""
            strUbigeo = ObjData.Rows(0).Item("UBIGEO")
            LISTA_DEPARTAMENTO()
            LISTA_PROVINCIA(strUbigeo)
            LISTA_DISTRITO(strUbigeo)
            ddl_depa.SelectedValue = strUbigeo.Substring(0, 2) + "0000"
            If strUbigeo.Substring(2, 4) = "0000" Then
                ddl_provi.SelectedValue = "all"
            Else
                ddl_provi.SelectedValue = strUbigeo.Substring(0, 4) + "00"
                If strUbigeo.Substring(4, 2) = "00" Then
                    ddl_dist.SelectedValue = "all"
                Else
                    ddl_dist.SelectedValue = strUbigeo
                End If
            End If
        End If
        If IsDBNull(ObjData.Rows(0).Item("OBJETIVO")) Then
            txt_obj.Text = ""
        Else
            txt_obj.Text = ObjData.Rows(0).Item("OBJETIVO")
        End If
        If IsDBNull(ObjData.Rows(0).Item("SNIP")) Then
            txt_snip.Text = ""
        Else
            txt_snip.Text = ObjData.Rows(0).Item("SNIP")
        End If

        If IsDBNull(ObjData.Rows(0).Item("TIPO_PROYECTO_ACTIVIDAD")) Then
            ddl_proy_act.SelectedValue = "all"
            ViewState("VSdllsnip") = 0
        Else
            ddl_proy_act.SelectedValue = ObjData.Rows(0).Item("TIPO_PROYECTO_ACTIVIDAD")
            ViewState("VStipod") = ObjData.Rows(0).Item("TIPO_PROYECTO_ACTIVIDAD")
            ViewState("VSdllsnip") = ViewState("VStipod")
        End If

        If IsDBNull(ObjData.Rows(0).Item("FECHA_VIABILIDAD")) Then
            txt_fecha.Text = ""
        Else
            txt_fecha.Text = ObjData.Rows(0).Item("FECHA_VIABILIDAD")
        End If
        If IsDBNull(ObjData.Rows(0).Item("ESTADO")) Then
            ddl_estado.SelectedValue = "all"
        Else
            ddl_estado.SelectedValue = ObjData.Rows(0).Item("ESTADO")
        End If

        If IsDBNull(ObjData.Rows(0).Item("PPER")) Then ' PPER
            ddl_pper.SelectedValue = "all"
        Else
            ddl_pper.SelectedValue = ObjData.Rows(0).Item("PPER")
            lista_producto(ObjData.Rows(0).Item("PPER"))
            ListaMonitoreador(ObjData.Rows(0).Item("PPER"))
            Lista_Especialista(ObjData.Rows(0).Item("PPER"))

        End If

        If IsDBNull(ObjData.Rows(0).Item("PRODUCTO")) Then
            ddl_producto.SelectedValue = "all"
        Else
            ddl_producto.SelectedValue = ObjData.Rows(0).Item("PRODUCTO")
        End If
        If IsDBNull(ObjData.Rows(0).Item("TIPO_PROYECTO_DES")) Then
            dll_TipoProyDES.SelectedValue = "all"
        Else
            dll_TipoProyDES.SelectedValue = ObjData.Rows(0).Item("TIPO_PROYECTO_DES")
        End If



        If IsDBNull(ObjData.Rows(0).Item("AMBITO")) Then
            ddl_ambito.SelectedValue = "all"
        Else
            ddl_ambito.SelectedValue = ObjData.Rows(0).Item("AMBITO")
        End If
        If IsDBNull(ObjData.Rows(0).Item("EJECUTOR")) Then
            ddl_ejec.SelectedValue = "all"
        Else
            ddl_ejec.SelectedValue = ObjData.Rows(0).Item("EJECUTOR")
        End If

        If IsDBNull(ObjData.Rows(0).Item("PERSONA_MONITOREO")) Then
            ddl_monitor.SelectedValue = "all"
        Else
            ddl_monitor.SelectedValue = ObjData.Rows(0).Item("PERSONA_MONITOREO")
        End If

        If IsDBNull(ObjData.Rows(0).Item("PERSONA_ESPECIALISTA")) Then
            ddl_especialista.SelectedValue = "all"
        Else
            ddl_especialista.SelectedValue = ObjData.Rows(0).Item("PERSONA_ESPECIALISTA")
        End If

        If IsDBNull(ObjData.Rows(0).Item("ANHIO_FIRMA_POA")) Then
            txt_firma.Text = ""
        Else
            txt_firma.Text = ObjData.Rows(0).Item("ANHIO_FIRMA_POA")
        End If
        If IsDBNull(ObjData.Rows(0).Item("MES_FIRMA_POA")) Then
            txt_mesfirma.Text = ""
        Else
            txt_mesfirma.Text = ObjData.Rows(0).Item("MES_FIRMA_POA")
        End If
        If IsDBNull(ObjData.Rows(0).Item("TIPO_CAMBIO_POA")) Then
            ddl_tipocambio.SelectedValue = "all"
        Else
            ddl_tipocambio.SelectedValue = ObjData.Rows(0).Item("TIPO_CAMBIO_POA")
        End If

        'Meta 1
        If IsDBNull(ObjData.Rows(0).Item("DESC_META")) Then
            txt_DescMt1.Text = ""
        Else
            txt_DescMt1.Text = ObjData.Rows(0).Item("DESC_META")
        End If
        If IsDBNull(ObjData.Rows(0).Item("META")) Then
            txt_mt1.Text = ""
        Else
            txt_mt1.Text = ObjData.Rows(0).Item("META")
        End If
        If IsDBNull(ObjData.Rows(0).Item("UNIDAD")) Then
            ddl_mt1.SelectedValue = ""
        Else
            ddl_mt1.SelectedValue = ObjData.Rows(0).Item("UNIDAD")
        End If

        'Meta 2
        If IsDBNull(ObjData.Rows(0).Item("DESC_META2")) Then
            txt_DescMt2.Text = ""
        Else
            txt_DescMt2.Text = ObjData.Rows(0).Item("DESC_META2")
        End If
        If IsDBNull(ObjData.Rows(0).Item("META2")) Then
            txt_mt2.Text = ""
        Else
            txt_mt2.Text = ObjData.Rows(0).Item("META2")
        End If
        If IsDBNull(ObjData.Rows(0).Item("UNIDAD2")) Then
            ddl_mt2.SelectedValue = ""
        Else
            ddl_mt2.SelectedValue = ObjData.Rows(0).Item("UNIDAD2")
        End If

        'Meta 3
        If IsDBNull(ObjData.Rows(0).Item("DESC_META3")) Then
            txt_DescMt3.Text = ""
        Else
            txt_DescMt3.Text = ObjData.Rows(0).Item("DESC_META3")
        End If
        If IsDBNull(ObjData.Rows(0).Item("META3")) Then
            txt_mt3.Text = ""
        Else
            txt_mt3.Text = ObjData.Rows(0).Item("META3")
        End If
        If IsDBNull(ObjData.Rows(0).Item("UNIDAD3")) Then
            ddl_mt3.SelectedValue = ""
        Else
            ddl_mt3.SelectedValue = ObjData.Rows(0).Item("UNIDAD3")
        End If

        If IsDBNull(ObjData.Rows(0).Item("DOCUMENTO")) Then
            txtdoc.Text = ""
        Else
            txtdoc.Text = ObjData.Rows(0).Item("DOCUMENTO")
        End If

        If IsDBNull(ObjData.Rows(0).Item("TIPO_ASIGNACION_RECURSO")) Then
            dll_TipoTransferencia.SelectedValue = "all"
        Else
            dll_TipoTransferencia.SelectedValue = ObjData.Rows(0).Item("TIPO_ASIGNACION_RECURSO")
        End If

        '.................
        If IsDBNull(ObjData.Rows(0).Item("COORDX")) Then
            txt_CoordX.Text = ""
        Else
            txt_CoordX.Text = ObjData.Rows(0).Item("COORDX")
        End If
        If IsDBNull(ObjData.Rows(0).Item("COORDY")) Then
            txt_CoordY.Text = ""
        Else
            txt_CoordY.Text = ObjData.Rows(0).Item("COORDY")
        End If
        If IsDBNull(ObjData.Rows(0).Item("OBSERVACION")) Then
            txt_Obs.Text = ""
        Else
            txt_Obs.Text = ObjData.Rows(0).Item("OBSERVACION")
        End If
        If IsDBNull(ObjData.Rows(0).Item("PERIODO_INICIO_PROY")) Then
            txtPeriodoIni.Text = ""
        Else
            txtPeriodoIni.Text = ObjData.Rows(0).Item("PERIODO_INICIO_PROY")
        End If
        If IsDBNull(ObjData.Rows(0).Item("PERIODO_FIN_PROY")) Then
            txtPeriodoFin.Text = ""
        Else
            txtPeriodoFin.Text = ObjData.Rows(0).Item("PERIODO_FIN_PROY")
        End If

        'Montos
        If IsDBNull(ObjData.Rows(0).Item("MONTO_TOTAL_INVERTIDO")) Then 'Es el monto total del proyecto
            txt_invertido.Text = ""
        Else
            txt_invertido.Text = ObjData.Rows(0).Item("MONTO_TOTAL_INVERTIDO")
        End If

        If IsDBNull(ObjData.Rows(0).Item("MONTO_RO")) Then
            txt_Monto_RO.Text = ""
        Else
            txt_Monto_RO.Text = ObjData.Rows(0).Item("MONTO_RO")
        End If
        If IsDBNull(ObjData.Rows(0).Item("MONTO_DYT")) Then
            txt_Monto_DT.Text = ""
        Else
            txt_Monto_DT.Text = ObjData.Rows(0).Item("MONTO_DYT")
        End If
        If IsDBNull(ObjData.Rows(0).Item("MONTO_INV_ANHIO")) Then
            txt_invaño.Text = ""
        Else
            txt_invaño.Text = ObjData.Rows(0).Item("MONTO_INV_ANHIO")
        End If
        If IsDBNull(ObjData.Rows(0).Item("MONTO_TRANSFERIDO")) Then
            txt_MontoTransferido.Text = ""
        Else
            txt_MontoTransferido.Text = ObjData.Rows(0).Item("MONTO_TRANSFERIDO")
        End If


        If IsDBNull(ObjData.Rows(0).Item("VERSION")) Then
            Label105.Text = ""
        Else
            Label105.Text = ObjData.Rows(0).Item("VERSION")
        End If

        If IsDBNull(ObjData.Rows(0).Item("ESTADO_REPROG")) Then
            ddl_estado_ingreso.SelectedValue = "all"
        Else
            ddl_estado_ingreso.SelectedValue = ObjData.Rows(0).Item("ESTADO_REPROG")
        End If

        'If IsDBNull(ObjData.Rows(0).Item("DESC_META")) Then
        '    txt_DescMt1.Text = ""
        'Else
        '    txt_DescMt1.Text = ObjData.Rows(0).Item("DESC_META")
        'End If

        'If IsDBNull(ObjData.Rows(0).Item("DESC_META")) Then
        '    txt_DescMt1.Text = ""
        'Else
        '    txt_DescMt1.Text = ObjData.Rows(0).Item("DESC_META")
        'End If

        ddl_tipocambio.Enabled = False
        chkb.Enabled = False
    End Sub

#End Region

#Region "COMPONENTE"
    'carga de grilla componente
    Public Sub CargarGrilla()
        gv_componente.DataSource = ViewState("dtcomponente")
        gv_componente.DataBind()
    End Sub

    Public Function ExistenciaComponente(ByVal strcomponente As Integer) As DataTable
        Dim objdata As MantenimientoPoaBC
        Dim objdt As DataTable
        'busca si el componente existe
        Try
            objdata = New MantenimientoPoaBC
            objdt = objdata.ExistenciaComponente(strcomponente)
            Return objdt
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    'editar componente
    Public Sub editar_poa_componente(ByVal poa As String, ByVal comp As String, ByVal Descripcion As String, ByVal version As String, ByVal pesocomp As String)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Try
            objMantenimientoPoaBC = New MantenimientoPoaBC
            objMantenimientoPoaBC.editar_poa_componente(poa, comp, Descripcion, version, pesocomp)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    'eliminar componente
    Public Sub delete_update_comp(ByVal poa As String, ByVal comp As Integer, ByVal ver As String)
        Dim delete_update_comp As ReprogramarPoaBC
        Try
            delete_update_comp = New ReprogramarPoaBC
            delete_update_comp.delete_update_comp(poa, comp, ver)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    'lista los historicos del componentes
    Public Function Listaidcompohistory(ByVal compoH As String) As DataTable
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim objDt As DataTable
        Try
            ObjMantenimientoPoaBC = New MantenimientoPoaBC
            objDt = ObjMantenimientoPoaBC.Listaidcompohistory(compoH)
            Return objDt
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Protected Sub btn_mas_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_mas.Click
        'agregamos una fila nueva en componente
        If txt_componen.Text = "" Then
            alerta.Mostrar_Alerta("Aviso", "Debe ingresar el nombre del Componente")
        Else
            Dim ver As Integer = ViewState("Version")
            If ViewState("VSGrillaComponenteINICIAL") Is Nothing Then
            Else
                If ViewState("VSGrillaComponenteINICIAL").Rows.Count > 0 Then
                    ver = ViewState("VSGrillaComponenteINICIAL").Rows(0).Item("version")
                End If
            End If
            If txt_peso.Text = "" Then
                txt_peso.Text = "0"
            End If
            Dim row As DataRow = ViewState("dtcomponente").NewRow()
            row("poa") = ViewState("VSPOA1").ToString
            row("componente") = txt_componen.Text.ToUpper
            row("version") = ver
            row("peso_componente") = CDec(txt_peso.Text)
            ViewState("dtcomponente").Rows.Add(row)
            CargarGrilla()
            LIMPIAR_COMPONENTE()
            alerta.Mostrar_Alerta("Aviso", "Componente agregado <br> <font color='0000FF'>Si desea que los cambios sean permanentes haga click en Guardar</font>")
        End If
    End Sub

    Protected Sub btn_menos_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_menos.Click
        'qliminamos las filas marcadas
        Dim dt As DataTable
        dt = New DataTable
        dt = ViewState("dtcomponente")
        Dim i As Integer
        Dim booEliminar As Boolean = False
        For i = gv_componente.Rows.Count - 1 To 0 Step -1
            Dim chkb As CheckBox = CType(gv_componente.Rows(i).FindControl("chkcmp"), CheckBox)
            If chkb.Checked = "true" Then
                booEliminar = True
                If Len(ViewState("dtcomponente").Rows(i).item("codigo").ToString) > 0 Then
                    Dim componente As Integer = ViewState("dtcomponente").Rows(i).item("codigo").ToString
                    Dim objdata As MantenimientoPoaBC
                    Dim objdt As DataTable
                    objdata = New MantenimientoPoaBC
                    objdt = objdata.ExistenciaComponente(componente)
                    If objdt.Rows.Count = 0 Then
                        dt.Rows.RemoveAt(i)
                        alerta.Mostrar_Alerta("Aviso", " Registro Eliminado <br> <font color='0000FF'> Si desea que los cambios sean permanentes haga click en Guardar </font>")
                    Else
                        alerta.Mostrar_Alerta("Aviso", "No se puede eliminar, el Componente esta siendo usado")
                    End If
                Else
                    dt.Rows.RemoveAt(i)
                    alerta.Mostrar_Alerta("Aviso", " Registro Eliminado <br> <font color='0000FF'> Si desea que los cambios sean permanentes haga click en Guardar </font>")
                End If
            End If
        Next
        ViewState("dtcomponente") = dt
        gv_componente.DataSource = ViewState("dtcomponente")
        gv_componente.DataBind()
        If booEliminar = False Then
            alerta.Mostrar_Alerta("Aviso", "Debe marcar al menos un checkbox")
        End If
    End Sub

    Protected Sub btn_guardComponente_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_guardComponente.Click

        'Verificamos si la grilla está siendo editada.
        If ViewState("EditComp") = 1 Then
            alerta.Mostrar_Alerta("Aviso", "Debe terminar la edición del componente antes de guardar")
            Exit Sub
        End If

        '1- Eliminamos lo que se quito de la BD
        Dim dtgrillainicial As New DataTable
        dtgrillainicial = ViewState("VSGrillaComponenteINICIAL") 'Llamamos los datos iniciales 
        Dim j = 0
        Dim K = 0
        Dim h = 0
        If dtgrillainicial Is Nothing Then  'Verificamos que existan datos iniciales
        Else
            For j = 0 To dtgrillainicial.Rows.Count - 1 'Recorremos los datos iniciales.                
                K = 0
                ViewState("VSCComp") = dtgrillainicial.Rows(j).Item("codigo").ToString
                For h = 0 To gv_componente.Rows.Count - 1 'Comparamos los datos actuales.                
                    Dim HF As HiddenField = CType(gv_componente.Rows(h).FindControl("codigo"), HiddenField)
                    If Convert.ToInt16(dtgrillainicial.Rows(j).Item("codigo").ToString) = Convert.ToInt16(IIf(HF.Value.ToString = "", 0, HF.Value.ToString)) Then
                        K = 1
                        Exit For
                    End If
                Next
                If K = 0 Then   'Si el codigo inicial ya no existe se elimina de la BD
                    delete_update_comp(ViewState("VSPOA1"), ViewState("VSCComp"), ViewState("Version"))
                End If
            Next
        End If

        '2 Verificamos si la suma de pesos es 100
        Dim peso As Integer
        Dim m As Integer
        For m = 0 To gv_componente.Rows.Count - 1   'Recorremos la grilla.
            Dim htxtPESO As Label = CType(gv_componente.Rows(m).FindControl("lblpeso"), Label)
            If htxtPESO.Text = "" Then  'Si hay una campo peso vacio, mostrar mensaje.
                alerta.Mostrar_Alerta("Aviso", "El campo Peso no debe estar vacio")
                Exit Sub
            Else    'Sumamos los pesos
                peso = peso + Convert.ToInt16(htxtPESO.Text)
            End If
        Next
        'Validamos que los pesos sumen 100
        If peso = 100 Then  'Si peso suma 100 se guardan datos.
        Else    'Si no suman Mostrar Mensaje.
            alerta.Mostrar_Alerta("Aviso", "Los Pesos deben sumar 100")
            'By Tigrito )05/07/2013): Commented
            'Exit Sub
        End If

        '3- GUARDAR
        Dim compoed As String
        Dim comphed As String
        Dim i As Integer
        Dim objgen As GeneralBC

        For i = 0 To gv_componente.Rows.Count - 1   'Recorremos la grilla Componente.
            'Capturamos el código.
            Dim htxtcod As HiddenField = CType(gv_componente.Rows(i).FindControl("codigo"), HiddenField)
            Dim codcomp As String = htxtcod.Value.ToString

            ' Verificamos si existe el codigo del componente 
            If codcomp = "" Then    '--NO existe
                objgen = New GeneralBC
                'Generamos los codigos
                compoed = objgen.GenerarCodigoNumeroString("POA_ACTIVIDAD_COMPONENTE", "COMPONENTE")
                comphed = objgen.GenerarCodigoNumero("POA_COMPONENTE_HISTORICO", "ID_POA_COMPONENTE")
                Dim DESCRIPCION As Label = CType(gv_componente.Rows(i).FindControl("lblcomponente"), Label)
                Dim htxtPESO As Label = CType(gv_componente.Rows(i).FindControl("lblpeso"), Label)
                Dim peso1 As Integer = Convert.ToInt16(htxtPESO.Text)
                'Insertamos el componente.
                insertar_componente(ViewState("VSPOA1"), compoed, DESCRIPCION.Text, ViewState("dtcomponente").Rows(i).Item("version"), comphed, peso1)

            Else    '--SI existe

                Dim DESCRIPCION As Label = CType(gv_componente.Rows(i).FindControl("lblcomponente"), Label)
                Dim htxtPESO As Label = CType(gv_componente.Rows(i).FindControl("lblpeso"), Label)
                Dim hfcodigoComponente As HiddenField = CType(gv_componente.Rows(i).FindControl("codigo"), HiddenField)
                Dim codigoComponente As Integer = hfcodigoComponente.Value.ToString
                Dim htxtversion As HiddenField = CType(gv_componente.Rows(i).FindControl("VERSION"), HiddenField)
                ViewState("VScodigoComponente") = codigoComponente
                ViewState("VSPeso") = Convert.ToInt16(htxtPESO.Text)
                ViewState("VScompoVersion") = htxtversion.Value.ToString
                'Editamos el componente.
                editar_poa_componente(ViewState("VSPOA1"), ViewState("VScodigoComponente"), DESCRIPCION.Text, ViewState("VScompoVersion"), ViewState("VSPeso"))
            End If

        Next

        alerta.Mostrar_Alerta("Aviso", "Los Componentes se Guardaron Correctamente")
        LISTA_COMPONENTE(ViewState("VSPOA1"))
        CargarGrillafisico2(ViewState("VSPOA1"))
        CargarGrillaComponente(ViewState("VSPOA1"))
        LIMPIARFISICO()



    End Sub

    'insertar componente
    Public Sub insertar_componente(ByVal poa As String, ByVal comp As String, ByVal Descripcion As String, ByVal version As String, ByVal comph As Integer, ByVal pesocomp As Integer)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Try
            objMantenimientoPoaBC = New MantenimientoPoaBC
            objMantenimientoPoaBC.insertar_componente(poa, comp, Descripcion, version, comph, pesocomp)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    'cargar grilla componente con filtro
    Public Sub CargarGrillaComponente(ByVal poa As String)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC

        Dim objData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC

        objData = objMantenimientoPoaBC.CargarGrillaComponente(poa)
        gv_componente.DataSource = objData
        ViewState("dtcomponente") = objData
        ViewState("VSGrillaComponenteINICIAL") = objData
        gv_componente.DataBind()
    End Sub

    Protected Sub gv_componente_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gv_componente.RowCancelingEdit
        ViewState("EditComp") = 0
        Me.gv_componente.EditIndex = -1
        Me.gv_componente.DataSource = ViewState("dtcomponente")
        Me.gv_componente.DataBind()
    End Sub

    Protected Sub gv_componente_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gv_componente.RowEditing
        ViewState("EditComp") = 1
        Me.gv_componente.EditIndex = e.NewEditIndex
        Me.gv_componente.DataSource = ViewState("dtcomponente")
        Me.gv_componente.DataBind()
    End Sub

    Protected Sub gv_componente_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv_componente.RowUpdating
        ViewState("EditComp") = 0
        Dim hfPOA As HiddenField = CType(gv_componente.Rows(e.RowIndex).FindControl("POA"), HiddenField)
        Dim txtComponente As TextBox = CType(gv_componente.Rows(e.RowIndex).FindControl("txtcp"), TextBox)
        Dim txt_peso As TextBox = CType(gv_componente.Rows(e.RowIndex).FindControl("TextBox50"), TextBox)
        Dim htxtversion As HiddenField = CType(gv_componente.Rows(e.RowIndex).FindControl("VERSION"), HiddenField)
        'Actualizar en session
        Dim dtComp As DataTable
        dtComp = New DataTable
        dtComp = ViewState("dtcomponente")
        dtComp.Rows(e.RowIndex).Item("poa") = hfPOA.Value
        dtComp.Rows(e.RowIndex).Item("componente") = txtComponente.Text
        dtComp.Rows(e.RowIndex).Item("peso_componente") = txt_peso.Text
        dtComp.Rows(e.RowIndex).Item("VERSION") = htxtversion.Value
        ViewState("dtcomponente") = dtComp
        Me.gv_componente.EditIndex = -1
        Me.gv_componente.DataSource = dtComp
        Me.gv_componente.DataBind()
    End Sub

    Protected Sub gv_componente_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv_componente.SelectedIndexChanged
        If ViewState("VSAccion") = "M" Then
            Dim htxtcodigo As HiddenField = CType(gv_componente.SelectedRow.FindControl("codigo"), HiddenField)
            Dim htxtversion As HiddenField = CType(gv_componente.SelectedRow.FindControl("VERSION"), HiddenField)
            Dim htxtPOA As HiddenField = CType(gv_componente.SelectedRow.FindControl("POA"), HiddenField)
            'captura de parametros
            ViewState("VScompoedit") = htxtcodigo.Value.ToString
            ViewState("VScompoPoa") = htxtPOA.Value.ToString
            ViewState("VScompoVersion") = htxtversion.Value.ToString
            ViewState("VSind") = gv_componente.SelectedIndex.ToString
        Else
            ViewState("VSind") = gv_componente.SelectedIndex.ToString
        End If
    End Sub

    Public Sub LISTA_COMPONENTE(ByVal poac As String)
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = New DataTable
        ObjData = ObjMantenimientoPoaBC.LISTA_COMPONENTE(poac)

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("descripcion2") = "--Seleccione--"
        drestadorow("componente") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_compnt.DataSource = ObjData
        ddl_compnt.DataTextField = "descripcion2"
        ddl_compnt.DataValueField = "componente"
        ddl_compnt.DataBind()
        ViewState("Componente") = ObjData
    End Sub

    'inserta actividad fisica
    Public Sub insertar_actividad_fisica(ByVal poa As String, ByVal comp As String, ByVal Descripcion As String, ByVal version As String, ByVal unidad As String, ByVal IDPF As Integer,
                                      ByVal MT1 As Decimal, ByVal MT2 As Decimal, ByVal MT3 As Decimal, ByVal MT4 As Decimal, ByVal MT5 As Decimal, ByVal MT6 As Decimal,
                                      ByVal MT7 As Decimal, ByVal MT8 As Decimal, ByVal MT9 As Decimal, ByVal MT10 As Decimal, ByVal MT11 As Decimal, ByVal MT12 As Decimal,
                                      ByVal MTA As Decimal, ByVal IDFH As Integer, ByVal IDPC As Integer, ByVal PESO As Integer, ByVal COD As String, ByVal MT As Decimal, ByVal MEAA As Decimal)

        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Try
            ObjMantenimientoPoaBC = New MantenimientoPoaBC
            ObjMantenimientoPoaBC.insertar_actividad_fisica(poa, comp, Descripcion, version, unidad, IDPF,
                                         MT1, MT2, MT3, MT4, MT5, MT6, MT7, MT8, MT9, MT10, MT11, MT12, MTA, IDFH, IDPC, PESO, COD, MT, MEAA)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub LIMPIAR_COMPONENTE()
        txt_componen.Text = ""
        txt_peso.Text = ""
    End Sub

#End Region

#Region "FISICO"
    'edita poa_fisico
    Public Sub editar_poa_fisico(ByVal comp As String, ByVal Descripcion As String, ByVal version As Integer, ByVal unidad As String, ByVal IDPF As Integer,
                                      ByVal MT1 As Decimal, ByVal MT2 As Decimal, ByVal MT3 As Decimal, ByVal MT4 As Decimal, ByVal MT5 As Decimal, ByVal MT6 As Decimal,
                                      ByVal MT7 As Decimal, ByVal MT8 As Decimal, ByVal MT9 As Decimal, ByVal MT10 As Decimal, ByVal MT11 As Decimal, ByVal MT12 As Decimal,
                                      ByVal MTA As Decimal, ByVal PESO As Integer, ByVal COD As String, ByVal MT As Decimal, ByVal MEAA As Decimal)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Try
            objMantenimientoPoaBC = New MantenimientoPoaBC
            objMantenimientoPoaBC.editar_poa_fisico(comp, Descripcion.ToUpper, version, unidad, IDPF, MT1, MT2, MT3, MT4, MT5, MT6, MT7, MT8, MT9, MT10, MT11, MT12, MTA, PESO, COD, MT, MEAA)
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    'carga grilla fisica 
    Public Sub CargarGrillafisico()
        gv_fisico.DataSource = ViewState("dtfisico")
        gv_fisico.DataBind()
    End Sub

    'elimina poa_fisico
    Public Sub delete_update_fis(ByVal poa As String, ByVal idfis As Integer, ByVal ver As String)
        Dim objdelete_update_fis As ReprogramarPoaBC
        Try
            objdelete_update_fis = New ReprogramarPoaBC
            objdelete_update_fis.delete_update_fis(poa, idfis, ver)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    'carga grilla fisica con filtro
    Public Sub CargarGrillafisico(ByVal poa As String)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Dim objData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC
        objData = objMantenimientoPoaBC.CargarGrillafisico(poa)
        gv_fisico.DataSource = objData
        gv_fisico.DataBind()
    End Sub

    'carga grilla fisica con filtro
    Public Sub CargarGrillafisico2(ByVal poa As String)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC

        Dim objData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC

        objData = objMantenimientoPoaBC.CargarGrillafisico(poa)
        gv_fisico.DataSource = objData
        ViewState("dtfisico") = objData
        gv_fisico.DataBind()
    End Sub

    'carga grilla fisica con filtro
    Public Sub CargarGrillafisico3(ByVal poa As String)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC

        Dim objData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC

        objData = objMantenimientoPoaBC.CargarGrillafisico(poa)
        gv_fisico.DataSource = objData
        ViewState("dtfisico") = objData
        gv_fisico.DataBind()
        Dim i As Integer
        For i = 0 To gv_fisico.Rows.Count - 1
            Dim ddl1 As DropDownList = gv_componente.Rows(i).FindControl("dll_cpte")
            ddl1 = ViewState("dtfisico").Rows(i).Item("componente")
        Next
    End Sub

    Protected Sub gv_fisico_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_fisico.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim strComp As String = ""
            Dim hfComp As HiddenField = CType(e.Row.FindControl("Componente"), HiddenField)
            Dim Comp As Label = CType(e.Row.FindControl("lblComp"), Label)
            Dim lblCOD As Label = CType(e.Row.FindControl("lblCOD"), Label)
            Dim lblCODCOM As Label = CType(e.Row.FindControl("lblCODCOM"), Label)
            If lblCODCOM Is Nothing Then
                lblCODCOM = CType(e.Row.FindControl("lblCODCOM1"), Label)
            End If
            Dim strCodigoComp As String()
            If Comp Is Nothing Then
                Dim ddlComp As DropDownList = CType(e.Row.FindControl("dll_cpte"), DropDownList)
                If ddlComp.SelectedIndex > 0 Then
                    strCodigoComp = ddlComp.SelectedItem.Text.Split("-")
                Else
                    Exit Sub
                End If
            Else
                strCodigoComp = Comp.Text.ToString.Split("-")
            End If
            If Comp Is Nothing Then
                Dim ddlComp As DropDownList = CType(e.Row.FindControl("dll_cpte"), DropDownList)
                If ddlComp.SelectedIndex > 0 Then
                    strComp = ddlComp.SelectedItem.Text
                End If
                Comp.Text = "222"
            Else
                strComp = Comp.Text
            End If

            Dim intContador As Int16 = 0
            Dim strCodigo As String()
            If lblCOD Is Nothing Then
                Dim lblCOD1 As TextBox = CType(e.Row.FindControl("lblCOD1"), TextBox)
                intContador = CuentaCaracter(lblCOD1.Text, ".")
                strCodigo = Split(lblCOD1.Text, ".")
            Else
                intContador = CuentaCaracter(lblCOD.Text, ".")
                strCodigo = Split(lblCOD.Text, ".")
            End If

            'da formato a celdas 
            Dim dtFisico As DataTable = New DataTable
            dtFisico = ViewState("dtcomponente")
            Dim compo As String
            If strCodigoComp.Length = 1 Then
                compo = strCodigoComp(0)
                lblCODCOM.Text = strCodigo(0).ToString
                Comp.Text = strCodigo(0) + " - " + Comp.Text
            Else
                compo = strCodigoComp(1).TrimStart
            End If
            For i As Int16 = 0 To dtFisico.Rows.Count - 1
                If dtFisico.Rows(i).Item("COMPONENTE").ToString = compo Then
                    If i Mod 2 = 0 Then
                        e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(200, 225, 250)
                        e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(200, 225, 250)
                        e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(200, 225, 250)
                        e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(200, 225, 250)
                    Else
                        e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(235, 250, 255)
                        e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(235, 250, 255)
                        e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(235, 250, 255)
                        e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(235, 250, 255)
                    End If
                    Exit For
                End If
            Next
            If intContador = 1 Then
                For n As Int16 = 4 To e.Row.Cells.Count - 1
                    e.Row.Cells(n).BackColor = Drawing.Color.LightGray
                Next
            Else
                For n As Int16 = 4 To e.Row.Cells.Count - 1
                    e.Row.Cells(n).BackColor = Drawing.Color.WhiteSmoke
                Next
            End If

            Dim lblenero As Label = CType(e.Row.FindControl("lblenero"), Label)
            If lblenero Is Nothing Then
            Else
                If lblenero.Text = "0" Then
                    lblenero.Text = ""
                End If
            End If
            Dim lblfeb As Label = CType(e.Row.FindControl("lblfeb"), Label)
            If lblfeb Is Nothing Then
            Else
                If lblfeb.Text = "0" Then
                    lblfeb.Text = ""
                End If
            End If
            Dim lblmar As Label = CType(e.Row.FindControl("lblmar"), Label)
            If lblmar Is Nothing Then
            Else
                If lblmar.Text = "0" Then
                    lblmar.Text = ""
                End If
            End If
            Dim lblabr As Label = CType(e.Row.FindControl("lblabr"), Label)
            If lblabr Is Nothing Then
            Else
                If lblabr.Text = "0" Then
                    lblabr.Text = ""
                End If
            End If
            Dim lblmay As Label = CType(e.Row.FindControl("lblmay"), Label)
            If lblmay Is Nothing Then
            Else
                If lblmay.Text = "0" Then
                    lblmay.Text = ""
                End If
            End If
            Dim lbljun As Label = CType(e.Row.FindControl("lbljun"), Label)
            If lbljun Is Nothing Then
            Else
                If lbljun.Text = "0" Then
                    lbljun.Text = ""
                End If
            End If
            Dim lbljul As Label = CType(e.Row.FindControl("lbljul"), Label)
            If lbljul Is Nothing Then
            Else
                If lbljul.Text = "0" Then
                    lbljul.Text = ""
                End If
            End If
            Dim lblago As Label = CType(e.Row.FindControl("lblago"), Label)
            If lblago Is Nothing Then
            Else
                If lblago.Text = "0" Then
                    lblago.Text = ""
                End If
            End If
            Dim lblset As Label = CType(e.Row.FindControl("lblset"), Label)
            If lblset Is Nothing Then
            Else
                If lblset.Text = "0" Then
                    lblset.Text = ""
                End If
            End If
            Dim lbloct As Label = CType(e.Row.FindControl("lbloct"), Label)
            If lbloct Is Nothing Then
            Else
                If lbloct.Text = "0" Then
                    lbloct.Text = ""
                End If
            End If
            Dim lblnov As Label = CType(e.Row.FindControl("lblnov"), Label)
            If lblnov Is Nothing Then
            Else
                If lblnov.Text = "0" Then
                    lblnov.Text = ""
                End If
            End If
            Dim lbldic As Label = CType(e.Row.FindControl("lbldic"), Label)
            If lbldic Is Nothing Then
            Else
                If lbldic.Text = "0" Then
                    lbldic.Text = ""
                End If
            End If
            Dim lblanual As Label = CType(e.Row.FindControl("lblanual"), Label)
            If lblanual Is Nothing Then
            Else
                If lblanual.Text = "0" Then
                    lblanual.Text = ""
                End If
            End If
        End If
        If ViewState("DIRECTIVA") = 2013 Then
            e.Row.Cells(7).Visible = False
            e.Row.Cells(8).Visible = False
        Else
            e.Row.Cells(7).Visible = True
            e.Row.Cells(8).Visible = True
        End If

        'Ocultar Componente para Proyecto y accion comun        'By sensey
        If ddl_proy_act.SelectedValue = "2" Or ddl_proy_act.SelectedValue = "3" Then
            'e.Row.Cells(3).Visible = False
        End If

    End Sub

    Protected Sub gv_fisico_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gv_fisico.RowEditing
        ViewState("EditFisico") = 1

        Me.gv_fisico.EditIndex = e.NewEditIndex
        Me.gv_fisico.DataSource = ViewState("dtfisico")
        Me.gv_fisico.DataBind()

        Dim objDt As DataTable = New DataTable
        objDt = ViewState("dtfisico")
        ViewState("VSidGrilla") = e.NewEditIndex

        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC

        ObjData = New DataTable
        ObjData = ObjMantenimientoPoaBC.LISTA_COMPONENTE(ViewState("VSPOA1"))

        If ObjData.Rows(ObjData.Rows.Count - 1).Item("COMPONENTE").ToString = "all" Then
            ObjData.Rows.RemoveAt(ObjData.Rows.Count - 1)
        End If

        'Lleno el combo
        ViewState("VSindf") = e.NewEditIndex
        Dim ddl1 As DropDownList = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("dll_cpte"), DropDownList)
        ddl1.DataSource = ObjData
        ddl1.DataTextField = "descripcion2"
        ddl1.DataValueField = "componente"
        ddl1.DataBind()
        ddl1.SelectedValue = objDt.Rows(e.NewEditIndex).Item("COMPONENTE")

        'Nuevo Inicio
        If objDt.Rows(e.NewEditIndex).Item("COMPONENTE") = ddl1.SelectedValue Then
            If e.NewEditIndex Mod 2 = 0 Then
                gv_fisico.Rows(e.NewEditIndex).Cells(0).BackColor = Drawing.Color.FromArgb(200, 225, 250)
                gv_fisico.Rows(e.NewEditIndex).Cells(1).BackColor = Drawing.Color.FromArgb(200, 225, 250)
                gv_fisico.Rows(e.NewEditIndex).Cells(2).BackColor = Drawing.Color.FromArgb(200, 225, 250)
                gv_fisico.Rows(e.NewEditIndex).Cells(3).BackColor = Drawing.Color.FromArgb(200, 225, 250)
            Else
                gv_fisico.Rows(e.NewEditIndex).Cells(0).BackColor = Drawing.Color.FromArgb(235, 250, 255)
                gv_fisico.Rows(e.NewEditIndex).Cells(1).BackColor = Drawing.Color.FromArgb(235, 250, 255)
                gv_fisico.Rows(e.NewEditIndex).Cells(2).BackColor = Drawing.Color.FromArgb(235, 250, 255)
                gv_fisico.Rows(e.NewEditIndex).Cells(3).BackColor = Drawing.Color.FromArgb(235, 250, 255)
            End If
        End If
        'Nuevo Fin

        Dim hfuni As HiddenField = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("hfUnidad1"), HiddenField)
        Dim ddl2 As DropDownList = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("dll_unid"), DropDownList)

        Dim ObjData2 As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData2 = New DataTable
        ObjData2 = ObjMantenimientoPoaBC.Lista_Unidades()
        If hfuni.Value = "" Then
            ddl2.DataSource = Nothing
            ddl2.DataBind()
        Else
            ddl2.DataSource = ObjData2
            ddl2.DataTextField = "DESCRIPCION"
            ddl2.DataValueField = "UNIDAD"
            ddl2.DataBind()
            ddl2.SelectedValue = objDt.Rows(e.NewEditIndex).Item("unidad")
            ViewState("ComboUnidad") = ObjData2
        End If
        Dim txtCodigo As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("lblCOD1"), TextBox)
        'metas
        Dim txt_ene As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_ene"), TextBox)
        Dim txt_feb As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_feb"), TextBox)
        Dim txt_mar As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_mar"), TextBox)
        Dim txt_abr As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_abr"), TextBox)
        Dim txt_may As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_may"), TextBox)
        Dim txt_jun As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_jun"), TextBox)
        Dim txt_jul As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_jul"), TextBox)
        Dim txt_ago As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_ago"), TextBox)
        Dim txt_set As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_set"), TextBox)
        Dim txt_oct As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_oct"), TextBox)
        Dim txt_nov As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_nov"), TextBox)
        Dim txt_dic As TextBox = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("txt_dic"), TextBox)
        Dim lblanual1 As Label = CType(gv_fisico.Rows(e.NewEditIndex).FindControl("lblanual1"), Label)
        If txt_ene Is Nothing Then
        Else
            If txt_ene.Text = "0" Then
                txt_ene.Text = ""
            End If
        End If
        If txt_feb Is Nothing Then
        Else
            If txt_feb.Text = "0" Then
                txt_feb.Text = ""
            End If
        End If
        If txt_mar Is Nothing Then
        Else
            If txt_mar.Text = "0" Then
                txt_mar.Text = ""
            End If
        End If
        If txt_abr Is Nothing Then
        Else
            If txt_abr.Text = "0" Then
                txt_abr.Text = ""
            End If
        End If
        If txt_may Is Nothing Then
        Else
            If txt_may.Text = "0" Then
                txt_may.Text = ""
            End If
        End If
        If txt_jun Is Nothing Then
        Else
            If txt_jun.Text = "0" Then
                txt_jun.Text = ""
            End If
        End If
        If txt_jul Is Nothing Then
        Else
            If txt_jul.Text = "0" Then
                txt_jul.Text = ""
            End If
        End If
        If txt_ago Is Nothing Then
        Else
            If txt_ago.Text = "0" Then
                txt_ago.Text = ""
            End If
        End If
        If txt_set Is Nothing Then
        Else
            If txt_set.Text = "0" Then
                txt_set.Text = ""
            End If
        End If
        If txt_oct Is Nothing Then
        Else
            If txt_oct.Text = "0" Then
                txt_oct.Text = ""
            End If
        End If
        If txt_nov Is Nothing Then
        Else
            If txt_nov.Text = "0" Then
                txt_nov.Text = ""
            End If
        End If
        If txt_dic Is Nothing Then
        Else
            If txt_dic.Text = "0" Then
                txt_dic.Text = ""
            End If
        End If
        If lblanual1 Is Nothing Then
        Else
            If lblanual1.Text = "0" Then
                lblanual1.Text = ""
            End If
        End If
        If ViewState("DIRECTIVA") = 2013 Then
            gv_fisico.Rows(e.NewEditIndex).Cells(7).Visible = False
            gv_fisico.Rows(e.NewEditIndex).Cells(8).Visible = False
        Else
            gv_fisico.Rows(e.NewEditIndex).Cells(7).Visible = True
            gv_fisico.Rows(e.NewEditIndex).Cells(8).Visible = True
        End If

    End Sub

    'carga grilla fisica con filtro
    Public Function CargarGrillafisico4(ByVal poa As String) As DataTable
        Dim objMantenimientoPoaBC As MantenimientoPoaBC

        Dim objData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC

        objData = objMantenimientoPoaBC.CargarGrillafisico(poa)
        gv_fisico.DataSource = objData
        ViewState("dtfisico") = objData
        ViewState("VSGrillaFisicoINICIAL") = objData
        gv_fisico.DataBind()
        Return objData
    End Function

    Protected Sub gv_fisico_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gv_fisico.RowCancelingEdit
        ViewState("EditFisico") = 0

        Me.gv_fisico.EditIndex = -1
        Me.gv_fisico.DataSource = ViewState("dtfisico")
        Me.gv_fisico.DataBind()
    End Sub

    Protected Sub gv_fisico_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv_fisico.RowUpdating
        ViewState("EditFisico") = 0

        Dim htxt As HiddenField = CType(gv_fisico.Rows(e.RowIndex).FindControl("Componente"), HiddenField)
        Dim hfuni As HiddenField = CType(gv_fisico.Rows(e.RowIndex).FindControl("hfUnidad"), HiddenField)
        Dim dllcomponetes As DropDownList = CType(gv_fisico.Rows(e.RowIndex).FindControl("dll_cpte"), DropDownList)
        Dim txtTareaActividad As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("TareaActividad"), TextBox)
        Dim dllunidades As DropDownList = CType(gv_fisico.Rows(e.RowIndex).FindControl("dll_unid"), DropDownList)
        Dim txt_ene As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_ene"), TextBox)
        Dim txt_feb As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_feb"), TextBox)
        Dim txt_mar As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_mar"), TextBox)
        Dim txt_abr As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_abr"), TextBox)
        Dim txt_may As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_may"), TextBox)
        Dim txt_jun As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_jun"), TextBox)
        Dim txt_jul As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_jul"), TextBox)
        Dim txt_ago As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_ago"), TextBox)
        Dim txt_set As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_set"), TextBox)
        Dim txt_oct As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_oct"), TextBox)
        Dim txt_nov As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_nov"), TextBox)
        Dim txt_dic As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_dic"), TextBox)
        Dim txt_peso As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txt_peso"), TextBox)
        Dim htxtversion As HiddenField = CType(gv_fisico.Rows(e.RowIndex).FindControl("hfVersion"), HiddenField)
        Dim lblCOD1 As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("lblCOD1"), TextBox)
        'By sensey
        Dim txtTotal As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txtTotal"), TextBox)
        Dim txtejec_acum_ant As TextBox = CType(gv_fisico.Rows(e.RowIndex).FindControl("txtejec_acum_ant"), TextBox)

        'Actualizar en session
        Dim dtfisico As DataTable
        dtfisico = New DataTable
        dtfisico = ViewState("dtfisico")
        dtfisico.Rows(e.RowIndex).Item("COMPONENTEDES") = dllcomponetes.SelectedItem.Text
        dtfisico.Rows(e.RowIndex).Item("COMPONENTE") = dllcomponetes.SelectedValue.ToString
        dtfisico.Rows(e.RowIndex).Item("TAREA") = txtTareaActividad.Text
        If ViewState("ComboUnidad") Is Nothing Then
            dtfisico.Rows(e.RowIndex).Item("unidades") = ""
        Else
            dtfisico.Rows(e.RowIndex).Item("unidades") = dllunidades.SelectedItem.Text
        End If
        dtfisico.Rows(e.RowIndex).Item("unidad") = dllunidades.SelectedValue.ToString
        dtfisico.Rows(e.RowIndex).Item("meta_01") = IIf(txt_ene.Text = "", 0, txt_ene.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_02") = IIf(txt_feb.Text = "", 0, txt_feb.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_03") = IIf(txt_mar.Text = "", 0, txt_mar.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_04") = IIf(txt_abr.Text = "", 0, txt_abr.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_05") = IIf(txt_may.Text = "", 0, txt_may.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_06") = IIf(txt_jun.Text = "", 0, txt_jun.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_07") = IIf(txt_jul.Text = "", 0, txt_jul.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_08") = IIf(txt_ago.Text = "", 0, txt_ago.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_09") = IIf(txt_set.Text = "", 0, txt_set.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_10") = IIf(txt_oct.Text = "", 0, txt_oct.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_11") = IIf(txt_nov.Text = "", 0, txt_nov.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_12") = IIf(txt_dic.Text = "", 0, txt_dic.Text)
        dtfisico.Rows(e.RowIndex).Item("meta_anual") = (Convert.ToDouble(IIf(txt_ene.Text = "", 0, txt_ene.Text)) + Convert.ToDouble(IIf(txt_feb.Text = "", 0, txt_feb.Text)) + _
                                                      Convert.ToDouble(IIf(txt_mar.Text = "", 0, txt_mar.Text)) + Convert.ToDouble(IIf(txt_abr.Text = "", 0, txt_abr.Text)) + _
                                                      Convert.ToDouble(IIf(txt_may.Text = "", 0, txt_may.Text)) + Convert.ToDouble(IIf(txt_jun.Text = "", 0, txt_jun.Text)) + _
                                                      Convert.ToDouble(IIf(txt_jul.Text = "", 0, txt_jul.Text)) + Convert.ToDouble(IIf(txt_ago.Text = "", 0, txt_ago.Text)) + _
                                                      Convert.ToDouble(IIf(txt_set.Text = "", 0, txt_set.Text)) + Convert.ToDouble(IIf(txt_oct.Text = "", 0, txt_oct.Text)) + _
                                                      Convert.ToDouble(IIf(txt_nov.Text = "", 0, txt_nov.Text)) + Convert.ToDouble(IIf(txt_dic.Text = "", 0, txt_dic.Text))).ToString
        dtfisico.Rows(e.RowIndex).Item("peso") = IIf(txt_peso.Text = "", 0, txt_peso.Text)
        dtfisico.Rows(e.RowIndex).Item("VERSION") = htxtversion.Value
        dtfisico.Rows(e.RowIndex).Item("CODIGO") = lblCOD1.Text
        dtfisico.Rows(e.RowIndex).Item("META_TOTAL") = txtTotal.Text
        dtfisico.Rows(e.RowIndex).Item("META_EJEC_ACUM_ANT") = txtejec_acum_ant.Text
        ViewState("dtfisico") = dtfisico
        Me.gv_fisico.EditIndex = -1
        Me.gv_fisico.DataSource = dtfisico
        Me.gv_fisico.DataBind()
    End Sub

    Protected Sub btn_guardFisico_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_guardFisico.Click
        Try

            If ViewState("EditFisico") = 1 Then
                alerta.Mostrar_Alerta("Aviso", "Debe terminar la edición de la meta física antes de guardar")
                Exit Sub
            End If

            '1- Eliminamos lo que se quito de la base de datos
            Dim dtgrillainicial As New DataTable
            dtgrillainicial = ViewState("VSGrillaFisicoINICIAL")
            If dtgrillainicial Is Nothing Then
            Else
                Dim j = 0
                Dim K = 0
                Dim h = 0
                For j = 0 To dtgrillainicial.Rows.Count - 1
                    K = 0
                    If gv_fisico.Rows.Count = 0 Then
                        'Commented by Tigrito 15/05/2013
                        'Con el 2do parámetro en 0... se borrará todos items de la BD del POA = VSPOA1
                        delete_update_fis(ViewState("VSPOA1"), 0, ViewState("Version"))
                    Else
                        ViewState("VSCfis") = dtgrillainicial.Rows(j).Item("ID_POA_ACTIVIDAD_FISICA").ToString
                        For h = 0 To gv_fisico.Rows.Count - 1
                            Dim HF As HiddenField = CType(gv_fisico.Rows(h).FindControl("idfisico"), HiddenField)
                            If HF.Value.ToString = "" Then
                                HF.Value = "0"
                            End If

                            If ViewState("VSCfis").ToString = "" Then
                                ViewState("VSCfis") = "0"
                            End If

                            If Convert.ToInt16(ViewState("VSCfis")).ToString = Convert.ToInt16(HF.Value.ToString) Then
                                K = 1
                                Exit For
                            End If
                        Next
                        If K = 0 Then
                            'Commented by Tigrito 15/05/2013
                            'Con el 2do parámetro en VSCfis... se borrará ese item de la BD del POA = VSPOA1
                            Dim objReporteDA As ReprogramarPoaBC
                            Dim objDt As DataTable

                            objReporteDA = New ReprogramarPoaBC
                            objDt = objReporteDA.Consulta_Existencia_Hijos_Metas_Fisicas(ViewState("VSPOA1"), ViewState("Version"), ViewState("VSCfis"))

                            If objDt.Rows(0).Item("EXISTE").ToString = 0 Then
                                delete_update_fis(ViewState("VSPOA1"), ViewState("VSCfis"), ViewState("Version"))
                                alerta.Mostrar_Alerta("Aviso", " Registro Eliminado Exitosamente")
                            Else
                                alerta.Mostrar_Alerta("Aviso", "No se puede eliminar, el registro esta siendo usado")
                                Exit Sub
                            End If

                        End If
                    End If
                Next
            End If

            ' 2- Verificamos el formato de los códigos

            Dim strCodigoX, strCodigoY, strCodigoZ As String()
            For Fi As Int16 = 0 To gv_fisico.Rows.Count - 1
                If Fi = 0 Then
                    Dim lblCOD As Label = CType(gv_fisico.Rows(Fi).FindControl("lblCOD"), Label)
                    Dim lblCODCOM As Label = CType(gv_fisico.Rows(Fi).FindControl("lblComp"), Label)
                    strCodigoZ = Split(lblCODCOM.Text, "-")
                    strCodigoX = Split(lblCOD.Text.ToString, ".") 'lblCOD
                    If strCodigoX(0) = strCodigoZ(0).ToString.TrimEnd.TrimStart Then   'lblCODCOM
                    Else
                        alerta.Mostrar_Alerta("Aviso", "Error de formato de códigos")
                        'By Tigrito 05/07/2013: Commented
                        'Exit Sub
                    End If
                Else
                    Dim lblCOD0 As Label = CType(gv_fisico.Rows(Fi - 1).FindControl("lblCOD"), Label)
                    Dim lblCOD As Label = CType(gv_fisico.Rows(Fi).FindControl("lblCOD"), Label)
                    Dim lblCODCOM As Label = CType(gv_fisico.Rows(Fi).FindControl("lblComp"), Label)
                    strCodigoX = Split(lblCOD0.Text, ".")
                    strCodigoY = Split(lblCOD.Text, ".")
                    strCodigoZ = Split(lblCODCOM.Text, "-")
                    If strCodigoY(0) = strCodigoZ(0).ToString.TrimEnd.TrimStart Then
                    Else
                        alerta.Mostrar_Alerta("Aviso", "Parece haber un error en el código de las tareas/actividades <br> del Componente " + strCodigoZ(1).ToString + ", el cual debe tener por ejemplo la forma: <br><div style='text-align:left'><table><tr><td style='width:50px'</td><td> 1.1  </td></tr><tr><td></td><td>&nbsp 1.1.1</td></tr><tr><td></td><td>&nbsp 1.1.2</td></tr><tr><td></td><td>1.2</td></tr></table></div>")
                        'By Tigrito )05/07/2013): Commented
                        'Exit Sub
                    End If
                    If strCodigoY.Count = strCodigoX.Count Then
                        For k As Int16 = 0 To strCodigoX.Count - 1
                            If k = strCodigoX.Count - 1 Then
                                If CInt(strCodigoX(k).ToString) = CInt(strCodigoY(k).ToString) - 1 And strCodigoX(k - 1) = strCodigoY(k - 1) Then
                                Else
                                    If (strCodigoY(k).ToString = 1 And CInt(strCodigoX(k - 1).ToString) = CInt(strCodigoY(k - 1).ToString) - 1) Then
                                    Else
                                        alerta.Mostrar_Alerta("Aviso", "Parece haber un error en el código de las tareas/actividades <br> del Componente " + strCodigoZ(1).ToString + ", el cual debe tener por ejemplo la forma: <br><div style='text-align:left'><table><tr><td style='width:50px'</td><td> 1.1  </td></tr><tr><td></td><td>&nbsp 1.1.1</td></tr><tr><td></td><td>&nbsp 1.1.2</td></tr><tr><td></td><td>1.2</td></tr></table></div>")
                                        'By Tigrito 05/07/2013: Commented
                                        'Exit Sub
                                    End If
                                End If
                            Else
                                If strCodigoX(k) = strCodigoY(k) Then
                                Else
                                    If strCodigoX(k) = strCodigoY(k) - 1 Then
                                    Else
                                        alerta.Mostrar_Alerta("Aviso", "Parece haber un error en el código de las tareas/actividades <br> del Componente " + strCodigoZ(1).ToString + ", el cual debe tener por ejemplo la forma: <br><div style='text-align:left'><table><tr><td style='width:50px'</td><td> 1.1  </td></tr><tr><td></td><td>&nbsp 1.1.1</td></tr><tr><td></td><td>&nbsp 1.1.2</td></tr><tr><td></td><td>1.2</td></tr></table></div>")
                                        'By Tigrito )05/07/2013): Commented
                                        'Exit Sub
                                    End If
                                End If

                            End If
                        Next
                    ElseIf strCodigoY.Count > strCodigoX.Count Then
                        If strCodigoY.Count - strCodigoX.Count = 1 Then
                            For k As Int16 = 0 To strCodigoX.Count - 2
                                If strCodigoY(k) = strCodigoX(k) Then
                                Else
                                    alerta.Mostrar_Alerta("Aviso", "Parece haber un error en el código de las tareas/actividades <br> del Componente " + strCodigoZ(1).ToString + ", el cual debe tener por ejemplo la forma: <br><div style='text-align:left'><table><tr><td style='width:50px'</td><td> 1.1  </td></tr><tr><td></td><td>&nbsp 1.1.1</td></tr><tr><td></td><td>&nbsp 1.1.2</td></tr><tr><td></td><td>1.2</td></tr></table></div>")
                                    'By Tigrito )05/07/2013): Commented
                                    'Exit Sub
                                End If
                            Next
                        Else
                            alerta.Mostrar_Alerta("Aviso", "Parece haber un error en el código de las tareas/actividades <br> del Componente " + strCodigoZ(1).ToString + ", el cual debe tener por ejemplo la forma: <br><div style='text-align:left'><table><tr><td style='width:50px'</td><td> 1.1  </td></tr><tr><td></td><td>&nbsp 1.1.1</td></tr><tr><td></td><td>&nbsp 1.1.2</td></tr><tr><td></td><td>1.2</td></tr></table></div>")
                            'By Tigrito )05/07/2013): Commented
                            'Exit Sub
                        End If
                    Else
                        If CInt(strCodigoY(strCodigoY.Count - 1)) = CInt(strCodigoX(strCodigoY.Count - 1)) + 1 Then
                            For k As Int16 = 0 To strCodigoY.Count - 2
                                If strCodigoY(k) = strCodigoX(k) Then
                                Else
                                    alerta.Mostrar_Alerta("Aviso", "Parece haber un error en el código de las tareas/actividades <br> del Componente " + strCodigoZ(1).ToString + ", el cual debe tener por ejemplo la forma: <br><div style='text-align:left'><table><tr><td style='width:50px'</td><td> 1.1  </td></tr><tr><td></td><td>&nbsp 1.1.1</td></tr><tr><td></td><td>&nbsp 1.1.2</td></tr><tr><td></td><td>1.2</td></tr></table></div>")
                                    Exit Sub
                                End If
                            Next
                        Else
                            alerta.Mostrar_Alerta("Aviso", "Parece haber un error en el código de las tareas/actividades <br> del Componente " + strCodigoZ(1).ToString + ", el cual debe tener por ejemplo la forma: <br><div style='text-align:left'><table><tr><td style='width:50px'</td><td> 1.1  </td></tr><tr><td></td><td>&nbsp 1.1.1</td></tr><tr><td></td><td>&nbsp 1.1.2</td></tr><tr><td></td><td>1.2</td></tr></table></div>")
                            'By Tigrito )05/07/2013): Commented
                            'Exit Sub
                        End If
                    End If
                End If
            Next

            ' 3- Verificamos si la suma es 100

            Dim intSuma, Rep As Integer
            For m0 As Integer = 0 To gv_fisico.Rows.Count - 1
                'capturamos componente, padre y peso        c , p y w		
                Dim htxtCompont As HiddenField = CType(gv_fisico.Rows(m0).FindControl("Componente"), HiddenField)
                Dim htxtPESO As Label = CType(gv_fisico.Rows(m0).FindControl("lblpeso"), Label)
                Dim lblCOD As Label = CType(gv_fisico.Rows(m0).FindControl("lblCOD"), Label)
                Dim strPadre As String
                If InStr(lblCOD.Text, ".") = 0 Then
                    strPadre = 0
                Else
                    strPadre = lblCOD.Text.Substring(0, IIf(InStrRev(lblCOD.Text, ".") = 0, 1, InStrRev(lblCOD.Text, ".") - 1))
                End If

                intSuma = CInt(htxtPESO.Text)
                Rep = 0
                If m0 > 0 Then
                    For q0 As Integer = 0 To m0 - 1
                        'capturamos componente y padre		c0 y p0		
                        Dim hfC0 As HiddenField = CType(gv_fisico.Rows(q0).FindControl("Componente"), HiddenField)
                        Dim lblCOD0 As Label = CType(gv_fisico.Rows(q0).FindControl("lblCOD"), Label)
                        Dim strPadre0 As String = lblCOD0.Text.Substring(0, IIf(InStrRev(lblCOD0.Text, ".") = 0, 1, InStrRev(lblCOD0.Text, ".") - 1))
                        If hfC0.Value = htxtCompont.Value And strPadre = strPadre0 Then
                            Rep = 1
                            Exit For
                        End If
                    Next
                End If
                If Rep = 0 Then
                    For r0 As Integer = m0 + 1 To gv_fisico.Rows.Count - 1
                        'capturamos componente y padre						c1 y p1		
                        Dim hfC1 As HiddenField = CType(gv_fisico.Rows(r0).FindControl("Componente"), HiddenField)
                        Dim lblCOD1 As Label = CType(gv_fisico.Rows(r0).FindControl("lblCOD"), Label)
                        Dim strPadre1 As String
                        If InStr(lblCOD1.Text, ".") = 0 Then
                            strPadre1 = 0
                        Else
                            strPadre1 = lblCOD1.Text.Substring(0, IIf(InStrRev(lblCOD1.Text, ".") = 0, 1, InStrRev(lblCOD1.Text, ".") - 1))
                        End If
                        If hfC1.Value = htxtCompont.Value And strPadre1 = strPadre Then
                            'Capturamos peso					w1		
                            Dim lblW1 As Label = CType(gv_fisico.Rows(r0).FindControl("lblpeso"), Label)
                            intSuma = intSuma + CInt(lblW1.Text)
                        End If
                    Next
                    If intSuma = 100 Then
                        intSuma = 0
                    Else
                        alerta.Mostrar_Alerta("Alerta", "Los Pesos deben sumar 100")
                        'By Tigrito )05/07/2013): Commented
                        'Exit Sub
                    End If
                End If
            Next

            'Guardamos

            Dim x As Integer
            Dim objgen3 As GeneralBC

            For x = 0 To gv_fisico.Rows.Count - 1 'Recorre la grilla
                Dim htxtidfisico As HiddenField = CType(gv_fisico.Rows(x).FindControl("idfisico"), HiddenField)
                ViewState("VSidfisico") = htxtidfisico.Value.ToString
                Dim codfis As String = ViewState("VSidfisico")

                If codfis = "" Then
                    codfis = "0"
                End If

                Dim htxtcompfis As String = ViewState("dtfisico").Rows(x).item("COMPONENTE")
                Dim componentefisico As String = htxtcompfis
                Dim desctarea As String = ViewState("dtfisico").Rows(x).item("TAREA").ToString.ToUpper
                Dim codunidad As String = IIf(IsDBNull(ViewState("dtfisico").Rows(x).item("UNIDAD")), "", ViewState("dtfisico").Rows(x).item("UNIDAD"))
                Dim Version As Integer = CInt(ViewState("dtfisico").Rows(x).item("VERSION").ToString)
                Dim strCodigo As String = ViewState("dtfisico").Rows(x).item("CODIGO").ToString
                Dim tarea As String = Server.HtmlDecode(gv_fisico.Rows(x).Cells(3).Text)
                Dim htxtM1 As Label = CType(gv_fisico.Rows(x).FindControl("lblenero"), Label)
                Dim htxtM2 As Label = CType(gv_fisico.Rows(x).FindControl("lblfeb"), Label)
                Dim htxtM3 As Label = CType(gv_fisico.Rows(x).FindControl("lblmar"), Label)
                Dim htxtM4 As Label = CType(gv_fisico.Rows(x).FindControl("lblabr"), Label)
                Dim htxtM5 As Label = CType(gv_fisico.Rows(x).FindControl("lblmay"), Label)
                Dim htxtM6 As Label = CType(gv_fisico.Rows(x).FindControl("lbljun"), Label)
                Dim htxtM7 As Label = CType(gv_fisico.Rows(x).FindControl("lbljul"), Label)
                Dim htxtM8 As Label = CType(gv_fisico.Rows(x).FindControl("lblago"), Label)
                Dim htxtM9 As Label = CType(gv_fisico.Rows(x).FindControl("lblset"), Label)
                Dim htxtM10 As Label = CType(gv_fisico.Rows(x).FindControl("lbloct"), Label)
                Dim htxtM11 As Label = CType(gv_fisico.Rows(x).FindControl("lblnov"), Label)
                Dim htxtM12 As Label = CType(gv_fisico.Rows(x).FindControl("lbldic"), Label)
                Dim m1 As Decimal = Convert.ToDecimal(IIf(htxtM1.Text = "", 0, htxtM1.Text))
                Dim m2 As Decimal = Convert.ToDecimal(IIf(htxtM2.Text = "", 0, htxtM2.Text))
                Dim m3 As Decimal = Convert.ToDecimal(IIf(htxtM3.Text = "", 0, htxtM3.Text))
                Dim m4 As Decimal = Convert.ToDecimal(IIf(htxtM4.Text = "", 0, htxtM4.Text))
                Dim m5 As Decimal = Convert.ToDecimal(IIf(htxtM5.Text = "", 0, htxtM5.Text))
                Dim m6 As Decimal = Convert.ToDecimal(IIf(htxtM6.Text = "", 0, htxtM6.Text))
                Dim m7 As Decimal = Convert.ToDecimal(IIf(htxtM7.Text = "", 0, htxtM7.Text))
                Dim m8 As Decimal = Convert.ToDecimal(IIf(htxtM8.Text = "", 0, htxtM8.Text))
                Dim m9 As Decimal = Convert.ToDecimal(IIf(htxtM9.Text = "", 0, htxtM9.Text))
                Dim m10 As Decimal = Convert.ToDecimal(IIf(htxtM10.Text = "", 0, htxtM10.Text))
                Dim m11 As Decimal = Convert.ToDecimal(IIf(htxtM11.Text = "", 0, htxtM11.Text))
                Dim m12 As Decimal = Convert.ToDecimal(IIf(htxtM12.Text = "", 0, htxtM12.Text))

                'By sensey nuevos campos
                Dim lblTotal As Label = CType(gv_fisico.Rows(x).FindControl("lblTotal"), Label)
                Dim lblejec_acum_ant As Label = CType(gv_fisico.Rows(x).FindControl("lblejec_acum_ant"), Label)

                Dim MetaTotal As Decimal = Convert.ToDecimal(IIf(lblTotal.Text = "", 0, lblTotal.Text))
                Dim EjAcAntFis As Decimal = Convert.ToDecimal(IIf(lblejec_acum_ant.Text = "", 0, lblejec_acum_ant.Text))

                Dim mtAn As String = Convert.ToDecimal(IIf(htxtM1.Text = "", 0, htxtM1.Text)) + Convert.ToDecimal(IIf(htxtM2.Text = "", 0, htxtM2.Text)) + Convert.ToDecimal(IIf(htxtM3.Text = "", 0, htxtM3.Text)) + Convert.ToDecimal(IIf(htxtM4.Text = "", 0, htxtM4.Text)) + Convert.ToDecimal(IIf(htxtM5.Text = "", 0, htxtM5.Text)) + Convert.ToDecimal(IIf(htxtM6.Text = "", 0, htxtM6.Text)) + Convert.ToDecimal(IIf(htxtM7.Text = "", 0, htxtM7.Text)) + Convert.ToDecimal(IIf(htxtM8.Text = "", 0, htxtM8.Text)) + Convert.ToDecimal(IIf(htxtM9.Text = "", 0, htxtM9.Text)) + Convert.ToDecimal(IIf(htxtM10.Text = "", 0, htxtM10.Text)) + Convert.ToDecimal(IIf(htxtM11.Text = "", 0, htxtM11.Text)) + Convert.ToDecimal(IIf(htxtM12.Text = "", 0, htxtM12.Text))
                Dim htxtPESO10 As Label = CType(gv_fisico.Rows(x).FindControl("lblpeso"), Label)
                Dim peso10 As Integer = Convert.ToInt16(htxtPESO10.Text)
                If codfis = "0" Then 'Si no existe
                    Dim idactFis As Integer
                    Dim IDFH As Integer
                    Dim versionf As String = ViewState("Version")
                    objgen3 = New GeneralBC
                    'Genera codigos
                    idactFis = objgen3.GenerarCodigoNumero("POA_ACTIVIDAD_FISICA", "ID_POA_ACTIVIDAD_FISICA")
                    IDFH = objgen3.GenerarCodigoNumero("POA_FISICA_HISTORICO", "ID_POA_FISICA_HISTORICA")
                    Dim htxtCompont As HiddenField = CType(gv_fisico.Rows(x).FindControl("componente"), HiddenField)
                    Dim htxtUnidad As HiddenField = CType(gv_fisico.Rows(x).FindControl("hfUnidad"), HiddenField)
                    Dim compof As String = htxtCompont.Value.ToString 'coidgo de componente de fila i
                    Dim datacomhf As DataTable = Listaidcompohistory(compof)
                    Dim compohistori As Integer = datacomhf.Rows(0).Item("id")
                    Dim unidf As String = htxtUnidad.Value.ToString

                    'Commented by Tigrito
                    'Insertamos una actividad
                    'by Sensey
                    'La insercion varia segun directiva
                    If ViewState("DIRECTIVA") = 2013 Then
                        insertar_actividad_fisica(ViewState("VSPOA1"), compof, desctarea, versionf, unidf, idactFis, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, mtAn, IDFH, compohistori, peso10, strCodigo, Nothing, Nothing)
                    Else
                        insertar_actividad_fisica(ViewState("VSPOA1"), compof, desctarea, versionf, unidf, idactFis, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, mtAn, IDFH, compohistori, peso10, strCodigo, MetaTotal, EjAcAntFis)
                    End If
                Else
                    Dim Total2 As Decimal
                    Total2 = Convert.ToDecimal(IIf(txt_1.Text = "", 0, txt_1.Text)) + Convert.ToDecimal(IIf(txt_2.Text = "", 0, txt_2.Text)) + Convert.ToDecimal(IIf(txt_3.Text = "", 0, txt_3.Text)) +
                    Convert.ToDecimal(IIf(txt_4.Text = "", 0, txt_4.Text)) + Convert.ToDecimal(IIf(txt_5.Text = "", 0, txt_5.Text)) + Convert.ToDecimal(IIf(txt_6.Text = "", 0, txt_6.Text)) +
                    Convert.ToDecimal(IIf(txt_7.Text = "", 0, txt_7.Text)) + Convert.ToDecimal(IIf(txt_8.Text = "", 0, txt_8.Text)) + Convert.ToDecimal(IIf(txt_9.Text = "", 0, txt_9.Text)) +
                    Convert.ToDecimal(IIf(txt_10.Text = "", 0, txt_10.Text)) + Convert.ToDecimal(IIf(txt_11.Text = "", 0, txt_11.Text)) + Convert.ToDecimal(IIf(txt_12.Text = "", 0, txt_12.Text))

                    'Editamos una actividad
                    'by Sensey
                    If ViewState("DIRECTIVA") = 2013 Then
                        editar_poa_fisico(componentefisico, desctarea, Version, codunidad, codfis, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, mtAn, peso10, strCodigo, Nothing, Nothing)
                    Else
                        editar_poa_fisico(componentefisico, desctarea, Version, codunidad, codfis, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, mtAn, peso10, strCodigo, MetaTotal, EjAcAntFis)
                    End If
                End If
            Next
            CargarGrillafisico4(ViewState("VSPOA1"))
            ' CargarGrillafisico2(ViewState("VSPOA1"))
            alerta.Mostrar_Alerta("Aviso", "Datos guardados correctamente")

        Catch ex As Exception
            alerta.Mostrar_Alerta("Aviso a sistemas", "Error")
        End Try

    End Sub

    Protected Sub btn_masfisico_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_masfisico.Click

        '---------------------- Permitir añadir metas fisicas sin unidades y sin padre (cabecera) ----------------------

        If ddl_compnt.SelectedValue = "all" Or txt_tarea.Text = "" Or ddl_unidadfisica.SelectedValue = "" Then
            alerta.Mostrar_Alerta("Aviso", "" & IIf(ddl_compnt.SelectedValue = "all", "<br/> - Debe seleccionar componente", "") & IIf(txt_tarea.Text = "", "<br/> - Debe colocar la descripción de tarea", "") & IIf(ddl_unidadfisica.SelectedValue = "", "<br/> - Debe seleccionar Unidad", ""))
            Exit Sub
        Else
            If Trim(txt_tarea.Text) = "" Then
                alerta.Mostrar_Alerta("Aviso", "Ingresar una Actividad")
            Else
                If ddl_unidadfisica.SelectedItem.ToString = "--Seleccione--" And CuentaCaracter(txtCOD.Text, ".") > 1 Then
                    alerta.Mostrar_Alerta("Aviso", "Debe seleccionar una unidad")
                Else
                    Dim VersionComponente As String
                    If ViewState("dtfisico").Rows.Count = 0 Then
                        VersionComponente = ViewState("Version")
                    Else
                        VersionComponente = ViewState("dtfisico").Rows(0).Item("version").ToString
                    End If

                    'Crear código
                    Dim strCodigo As String()
                    strCodigo = ddl_compnt.SelectedItem.ToString.Split("-") 'txtCOD.Text

                    Dim rowfs As DataRow = ViewState("dtfisico").NewRow()
                    rowfs("Componente") = ddl_compnt.SelectedValue.ToString
                    rowfs("ComponenteDes") = ddl_compnt.SelectedItem.ToString 'strCodigo(1).TrimStart
                    rowfs("unidad") = ddl_unidadfisica.SelectedValue.ToString

                    If ddl_unidadfisica.SelectedItem.ToString = "--Seleccione--" Then
                        rowfs("unidades") = ""
                    Else
                        rowfs("unidades") = ddl_unidadfisica.SelectedItem.ToString
                    End If

                    rowfs("Tarea") = txt_tarea.Text.ToUpper
                    rowfs("meta_01") = IIf(txt_1.Text = "", 0, txt_1.Text)
                    rowfs("meta_02") = IIf(txt_2.Text = "", 0, txt_2.Text)
                    rowfs("meta_03") = IIf(txt_3.Text = "", 0, txt_3.Text)
                    rowfs("meta_04") = IIf(txt_4.Text = "", 0, txt_4.Text)
                    rowfs("meta_05") = IIf(txt_5.Text = "", 0, txt_5.Text)
                    rowfs("meta_06") = IIf(txt_6.Text = "", 0, txt_6.Text)
                    rowfs("meta_07") = IIf(txt_7.Text = "", 0, txt_7.Text)
                    rowfs("meta_08") = IIf(txt_8.Text = "", 0, txt_8.Text)
                    rowfs("meta_09") = IIf(txt_9.Text = "", 0, txt_9.Text)
                    rowfs("meta_10") = IIf(txt_10.Text = "", 0, txt_10.Text)
                    rowfs("meta_11") = IIf(txt_11.Text = "", 0, txt_11.Text)
                    rowfs("meta_12") = IIf(txt_12.Text = "", 0, txt_12.Text)

                    rowfs("meta_anual") = Convert.ToDecimal(IIf(txt_1.Text = "", 0, txt_1.Text)) + Convert.ToDecimal(IIf(txt_2.Text = "", 0, txt_2.Text)) + Convert.ToDecimal(IIf(txt_3.Text = "", 0, txt_3.Text)) +
                    Convert.ToDecimal(IIf(txt_4.Text = "", 0, txt_4.Text)) + Convert.ToDecimal(IIf(txt_5.Text = "", 0, txt_5.Text)) + Convert.ToDecimal(IIf(txt_6.Text = "", 0, txt_6.Text)) +
                    Convert.ToDecimal(IIf(txt_7.Text = "", 0, txt_7.Text)) + Convert.ToDecimal(IIf(txt_8.Text = "", 0, txt_8.Text)) + Convert.ToDecimal(IIf(txt_9.Text = "", 0, txt_9.Text)) +
                    Convert.ToDecimal(IIf(txt_10.Text = "", 0, txt_10.Text)) + Convert.ToDecimal(IIf(txt_11.Text = "", 0, txt_11.Text)) + Convert.ToDecimal(IIf(txt_12.Text = "", 0, txt_12.Text))
                    rowfs("peso") = IIf(txtpesoFisico.Text = "", 0, txtpesoFisico.Text)
                    rowfs("VERSION") = VersionComponente
                    rowfs("CODIGO") = strCodigo(0).TrimEnd & "." & (gv_fisico.Rows.Count + 1).ToString.TrimStart

                    'By Sensey: Nuevos campos
                    rowfs("META_TOTAL") = IIf(txtTotalFis.Text = "", 0, txtTotalFis.Text)
                    rowfs("META_EJEC_ACUM_ANT") = IIf(txtEjAcAntFis.Text = "", 0, txtEjAcAntFis.Text)

                    'By Tigrito: Añadimos las filas a dtfisico
                    ViewState("dtfisico").Rows.Add(rowfs)

                    'By Tigrito: Creo que aquí es donde se ordena el gridview... es decir dv obtiene la tabla
                    'pero dv es un DataView el cual permite ordenar entre otras cosas
                    Dim dv As DataView = New DataView(ViewState("dtfisico"), "1=1", "CODIGO", DataViewRowState.CurrentRows)

                    'By Tigrito: Cambiando el ordenamiento
                    dv.Sort = "CODIGO ASC"

                    ViewState("dtfisico") = dv.ToTable
                    LIMPIARFISICO()
                End If
            End If
        End If
        CargarGrillafisico()
        alerta.Mostrar_Alerta("Aviso", "Registro agregado <br> <font color='0000FF'>Si desea que los cambios sean permanentes haga click en Guardar </font>")
    End Sub

    Private Function BuscarHermano(ByVal strComp As String) As String
        'busca codigo con el mismo padre
        Dim strCodigo As String = ""
        Dim dt As DataTable
        dt = New DataTable
        Dim vst As DataView
        vst = New DataView(ViewState("dtfisico"), "", "CODIGO DESC", DataViewRowState.CurrentRows)
        If vst.Count = 0 Then
            strCodigo = strCodigo + txtCOD.Text + ".1"
        Else
            dt = vst.ToTable
            strCodigo = dt.Rows(0).Item("CODIGO").ToString()
            Dim strPart As String()
            strPart = Split(strCodigo, ".")
            strCodigo = ""
            For i As Int16 = 0 To strPart.Length - 2
                strCodigo = strCodigo + strPart(i) + "."
            Next
            strCodigo = strCodigo + (CInt(strPart(strPart.Length - 1)) + 1).ToString
        End If
        Return strCodigo
    End Function

    Protected Sub btn_menosFisico_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_menosFisico.Click
        'elimina act fisicas maarcadas
        Dim i As Integer
        Dim booEliminar As Boolean = False
        For i = gv_fisico.Rows.Count - 1 To 0 Step -1
            Dim chkb As CheckBox = CType(gv_fisico.Rows(i).FindControl("chkcmp"), CheckBox)
            If chkb.Checked = "true" Then
                ViewState("dtfisico").Rows.RemoveAt(i)
                booEliminar = True
                alerta.Mostrar_Alerta("Aviso", " Registro Eliminado <br> <font color='0000FF'> Si desea que los cambios sean permanentes haga click en Guardar </font>")
            End If
        Next
        gv_fisico.DataSource = ViewState("dtfisico")
        gv_fisico.DataBind()
        If booEliminar = False Then
            alerta.Mostrar_Alerta("Aviso", "Debe marcar al menos un checkbox")
        End If
    End Sub

    Protected Sub LIMPIARFISICO()
        txt_1.Text = ""
        txt_2.Text = ""
        txt_3.Text = ""
        txt_4.Text = ""
        txt_5.Text = ""
        txt_6.Text = ""
        txt_7.Text = ""
        txt_8.Text = ""
        txt_9.Text = ""
        txt_10.Text = ""
        txt_11.Text = ""
        txt_12.Text = ""
        txt_tarea.Text = ""
        ddl_unidadfisica.SelectedValue = ""
        ddl_compnt.SelectedValue = "all"
        txtpesoFisico.Text = ""
        txtCOD.Text = ""
        txtTotalFis.Text = ""
        txtEjAcAntFis.Text = ""
    End Sub

#End Region

#Region "FINANCIERO"

    Public Sub lista_GENERICA()
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = ObjMantenimientoPoaBC.lista_GENERICA()

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("DESCRIPCION") = "--Seleccione--"
        drestadorow("GENERICA_GASTOS") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_generica.DataSource = ObjData
        ddl_generica.DataTextField = "DESCRIPCION"
        ddl_generica.DataValueField = "GENERICA_GASTOS"
        ddl_generica.DataBind()
        ddl_generica.SelectedValue = "all"
    End Sub

    Public Sub lista_ESPECIFICA2(ByVal generica As String)
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = ObjMantenimientoPoaBC.lista_ESPECIFICA2(generica)
        'carga especifica segun generica seleccionada
        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("DESCRIPCION2") = "--Seleccione--"
        drestadorow("ESPECIFICA_GASTO") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl_especifica.DataSource = ObjData
        ddl_especifica.DataTextField = Server.HtmlDecode("DESCRIPCION2")
        ddl_especifica.DataValueField = "ESPECIFICA_GASTO"
        ddl_especifica.DataBind()
    End Sub

    'edita poa financiera
    Public Sub editar_poa_financiero(ByVal GENE As String, ByVal ESPEC As String, ByVal version As Integer, ByVal IDPFN As Integer,
                                        ByVal MT1 As Decimal, ByVal MT2 As Decimal, ByVal MT3 As Decimal, ByVal MT4 As Decimal, ByVal MT5 As Decimal, ByVal MT6 As Decimal,
                                        ByVal MT7 As Decimal, ByVal MT8 As Decimal, ByVal MT9 As Decimal, ByVal MT10 As Decimal, ByVal MT11 As Decimal, ByVal MT12 As Decimal,
                                        ByVal MTAF As Decimal, ByVal MT As Decimal, ByVal MEAA As Decimal, ByVal EJECUTORA As Decimal, ByVal DEVIDA As Decimal, ByVal OTROS As Decimal)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC

        Try
            objMantenimientoPoaBC = New MantenimientoPoaBC
            objMantenimientoPoaBC.editar_poa_financiero(GENE, ESPEC, version, IDPFN, Replace(MT1, ",", ""), Replace(MT2, ",", ""), Replace(MT3, ",", ""), Replace(MT4, ",", ""),
                                                        Replace(MT5, ",", ""), Replace(MT6, ",", ""), Replace(MT7, ",", ""), Replace(MT8, ",", ""), Replace(MT9, ",", ""),
                                                        Replace(MT10, ",", ""), Replace(MT11, ",", ""), Replace(MT12, ",", ""), Replace(MTAF, ",", ""),
                                                        Replace(MT, ",", ""), Replace(MEAA, ",", ""), Replace(EJECUTORA, ",", ""), Replace(DEVIDA, ",", ""), Replace(OTROS, ",", ""))
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btn_masfinan_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_masfinan.Click
        'agregamos nueva fila a grilla
        Dim tabla() As String
        If ddl_generica.SelectedValue = "all" Then
            alerta.Mostrar_Alerta("Error", "Debe seleccionar una Generica de Gastos ")
            Exit Sub
        Else
            If ddl_especifica.SelectedValue = "all" Then
                alerta.Mostrar_Alerta("Error", "Debe seleccionar una Especifica de Gastos ")
                Exit Sub
            End If
            Dim VersionFinanciero As String
            If ViewState("dtfinanciero").Rows.Count = 0 Then
                VersionFinanciero = ViewState("Version")
            Else
                VersionFinanciero = ViewState("dtfinanciero").Rows(0).Item("version").ToString
            End If
            Dim rowfn As DataRow = ViewState("dtfinanciero").NewRow()
            rowfn("ESPECIFICA_GASTO") = ddl_especifica.SelectedValue.ToString
            ViewState("VScadena") = ddl_especifica.SelectedItem.ToString
            tabla = Split(ViewState("VScadena"), "-", 2)
            rowfn("ESPECIFICA_GASTODES") = tabla(1)
            rowfn("GENERICA_GASTO") = ddl_generica.SelectedValue.ToString
            rowfn("GENERICA_GASTODES") = ddl_generica.SelectedItem.ToString
            rowfn("meta_01") = IIf(txt_1f.Text = "", 0, txt_1f.Text)
            rowfn("meta_02") = IIf(txt_2f.Text = "", 0, txt_2f.Text)
            rowfn("meta_03") = IIf(txt_3f.Text = "", 0, txt_3f.Text)
            rowfn("meta_04") = IIf(txt_4f.Text = "", 0, txt_4f.Text)
            rowfn("meta_05") = IIf(txt_5f.Text = "", 0, txt_5f.Text)
            rowfn("meta_06") = IIf(txt_6f.Text = "", 0, txt_6f.Text)
            rowfn("meta_07") = IIf(txt_7f.Text = "", 0, txt_7f.Text)
            rowfn("meta_08") = IIf(txt_8f.Text = "", 0, txt_8f.Text)
            rowfn("meta_09") = IIf(txt_9f.Text = "", 0, txt_9f.Text)
            rowfn("meta_10") = IIf(txt_10f.Text = "", 0, txt_10f.Text)
            rowfn("meta_11") = IIf(txt_11f.Text = "", 0, txt_11f.Text)
            rowfn("meta_12") = IIf(txt_12f.Text = "", 0, txt_12f.Text)
            rowfn("meta_anual") = Convert.ToDecimal(IIf(txt_1f.Text = "", 0, txt_1f.Text)) + Convert.ToDecimal(IIf(txt_2f.Text = "", 0, txt_2f.Text)) + Convert.ToDecimal(IIf(txt_3f.Text = "", 0, txt_3f.Text)) +
                Convert.ToDecimal(IIf(txt_4f.Text = "", 0, txt_4f.Text)) + Convert.ToDecimal(IIf(txt_5f.Text = "", 0, txt_5f.Text)) + Convert.ToDecimal(IIf(txt_6f.Text = "", 0, txt_6f.Text)) +
                Convert.ToDecimal(IIf(txt_7f.Text = "", 0, txt_7f.Text)) + Convert.ToDecimal(IIf(txt_8f.Text = "", 0, txt_8f.Text)) + Convert.ToDecimal(IIf(txt_9f.Text = "", 0, txt_9f.Text)) +
                Convert.ToDecimal(IIf(txt_10f.Text = "", 0, txt_10f.Text)) + Convert.ToDecimal(IIf(txt_11f.Text = "", 0, txt_11f.Text)) + Convert.ToDecimal(IIf(txt_12f.Text = "", 0, txt_12f.Text))
            rowfn("version") = VersionFinanciero

            'By Sensey
            rowfn("META_TOTAL") = IIf(txtMetaTotalFin.Text = "", 0, txtMetaTotalFin.Text)
            rowfn("META_EJEC_ACUM_ANT") = IIf(txtMetaEjecacAntFin.Text = "", 0, txtMetaEjecacAntFin.Text)
            rowfn("EJECUTORA") = IIf(txtEjecutora.Text = "", 0, txtEjecutora.Text)
            rowfn("DEVIDA") = IIf(txtDevida.Text = "", 0, txtDevida.Text)
            rowfn("OTROS") = IIf(txtOtros.Text = "", 0, txtOtros.Text)

            ViewState("dtfinanciero").Rows.Add(rowfn)
        End If
        CargarGrillafinanciero()
        LIMPIARFINANCIERA()
        alerta.Mostrar_Alerta("Aviso", "Registro agregado <br> <font color='0000FF'>Si desea que los cambios sean permanentes haga click en Guardar </font>")
    End Sub

    'carga grilla financiera
    Public Sub CargarGrillafinanciero()
        gv_actfinan.DataSource = ViewState("dtfinanciero")
        gv_actfinan.DataBind()
    End Sub

    'carga grilla financiera con filtro
    Public Sub CargarGrillafinanciero(ByVal poa As String)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Dim objData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC
        objData = objMantenimientoPoaBC.CargarGrillafinanciero(poa)
        gv_actfinan.DataSource = objData
        gv_actfinan.DataBind()
    End Sub

    'carga grilla financiera con filtro
    Public Sub CargarGrillafinanciero2(ByVal poa As String)
        Dim objMantenimientoPoaBC As MantenimientoPoaBC
        Dim objData As DataTable
        objMantenimientoPoaBC = New MantenimientoPoaBC
        objData = objMantenimientoPoaBC.CargarGrillafinanciero(poa)
        gv_actfinan.DataSource = objData
        ViewState("dtfinanciero") = objData
        ViewState("VSGrillaFinancieroINICIAL") = objData
        gv_actfinan.DataBind()
    End Sub

    Protected Sub gv_actfinan_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gv_actfinan.RowCancelingEdit
        ViewState("EditFinanciero") = 0
        Me.gv_actfinan.EditIndex = -1
        Me.gv_actfinan.DataSource = ViewState("dtfinanciero")
        Me.gv_actfinan.DataBind()
    End Sub

    Private _total1, _total2, _total3, _total4, _total5, _total6, _total7, _total8, _total9, _total10, _total11, _total12, _totalR, _totalMT, _totalMEAA, _totalEjecutora, _totalDevida, _totalOtros As Double
    Protected Sub gv_actfinan_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_actfinan.RowDataBound
        If ViewState("EditFinanciero") = 0 Then
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim label1 As Label = CType(e.Row.FindControl("lblFinEne"), Label)
                Dim label2 As Label = CType(e.Row.FindControl("lblFinFeb"), Label)
                Dim label3 As Label = CType(e.Row.FindControl("lblFinMar"), Label)
                Dim label4 As Label = CType(e.Row.FindControl("lblFinAbr"), Label)
                Dim label5 As Label = CType(e.Row.FindControl("lblFinMay"), Label)
                Dim label6 As Label = CType(e.Row.FindControl("lblFinJun"), Label)
                Dim label7 As Label = CType(e.Row.FindControl("lblFinJul"), Label)
                Dim label8 As Label = CType(e.Row.FindControl("lblFinAgo"), Label)
                Dim label9 As Label = CType(e.Row.FindControl("lblFinSet"), Label)
                Dim label10 As Label = CType(e.Row.FindControl("lblFinOct"), Label)
                Dim label11 As Label = CType(e.Row.FindControl("lblFinNov"), Label)
                Dim label12 As Label = CType(e.Row.FindControl("lblFinDic"), Label)
                Dim labelR As Label = CType(e.Row.FindControl("lblFinTotal"), Label)
                'By Sensey
                Dim lblMetaTotal As Label = CType(e.Row.FindControl("lblMetaTotal"), Label)
                Dim lblmetaejecacumant As Label = CType(e.Row.FindControl("lblmetaejecacumant"), Label)
                Dim lblEjecutora As Label = CType(e.Row.FindControl("lblEjecutora"), Label)
                Dim lblDevida As Label = CType(e.Row.FindControl("lblDevida"), Label)
                Dim lblOtros As Label = CType(e.Row.FindControl("lblOtros"), Label)
                Dim priceMT As Decimal = Convert.ToDecimal(IIf(lblMetaTotal.Text = "", 0, lblMetaTotal.Text))
                Me._totalMT = Me._totalMT + priceMT
                Dim priceMEAA As Decimal = Convert.ToDecimal(IIf(lblmetaejecacumant.Text = "", 0, lblmetaejecacumant.Text))
                Me._totalMEAA = Me._totalMEAA + priceMEAA
                Dim priceEjecutora As Decimal = Convert.ToDecimal(IIf(lblEjecutora.Text = "", 0, lblEjecutora.Text))
                Me._totalEjecutora = Me._totalEjecutora + priceEjecutora
                Dim priceDevida As Decimal = Convert.ToDecimal(IIf(lblDevida.Text = "", 0, lblDevida.Text))
                Me._totalDevida = Me._totalDevida + priceDevida
                Dim priceOtros As Decimal = Convert.ToDecimal(IIf(lblOtros.Text = "", 0, lblOtros.Text))
                Me._totalOtros = Me._totalOtros + priceOtros

                Dim price1 As Decimal = Convert.ToDecimal(IIf(label1.Text = "", 0, label1.Text))
                Me._total1 = Me._total1 + price1
                Dim price2 As Decimal = Convert.ToDecimal(IIf(label2.Text = "", 0, label2.Text))
                Me._total2 = Me._total2 + price2
                Dim price3 As Decimal = Convert.ToDecimal(IIf(label3.Text = "", 0, label3.Text))
                Me._total3 = Me._total3 + price3
                Dim price4 As Decimal = Convert.ToDecimal(IIf(label4.Text = "", 0, label4.Text))
                Me._total4 = Me._total4 + price4
                Dim price5 As Decimal = Convert.ToDecimal(IIf(label5.Text = "", 0, label5.Text))
                Me._total5 = Me._total5 + price5
                Dim price6 As Decimal = Convert.ToDecimal(IIf(label6.Text = "", 0, label6.Text))
                Me._total6 = Me._total6 + price6
                Dim price7 As Decimal = Convert.ToDecimal(IIf(label7.Text = "", 0, label7.Text))
                Me._total7 = Me._total7 + price7
                Dim price8 As Decimal = Convert.ToDecimal(IIf(label8.Text = "", 0, label8.Text))
                Me._total8 = Me._total8 + price8
                Dim price9 As Decimal = Convert.ToDecimal(IIf(label9.Text = "", 0, label9.Text))
                Me._total9 = Me._total9 + price9
                Dim price10 As Decimal = Convert.ToDecimal(IIf(label10.Text = "", 0, label10.Text))
                Me._total10 = Me._total10 + price10
                Dim price11 As Decimal = Convert.ToDecimal(IIf(label11.Text = "", 0, label11.Text))
                Me._total11 = Me._total11 + price11
                Dim price12 As Decimal = Convert.ToDecimal(IIf(label12.Text = "", 0, label12.Text))
                Me._total12 = Me._total12 + price12
                Dim priceR As Decimal = Convert.ToDecimal(IIf(labelR.Text = "", 0, labelR.Text))
                Me._totalR = Me._totalR + priceR

            ElseIf e.Row.RowType = DataControlRowType.Footer Then
                e.Row.HorizontalAlign = HorizontalAlign.Right
                'By Sensey
                e.Row.Cells(6).Text = Me._totalMT.ToString("##,##0.00")
                e.Row.Cells(7).Text = Me._totalMEAA.ToString("##,##0.00")
                e.Row.Cells(8).Text = Me._totalEjecutora.ToString("##,##0.00")
                e.Row.Cells(9).Text = Me._totalDevida.ToString("##,##0.00")
                e.Row.Cells(10).Text = Me._totalOtros.ToString("##,##0.00")

                e.Row.Cells(11).Text = Me._total1.ToString("##,##0.00")
                e.Row.Cells(12).Text = Me._total2.ToString("##,##0.00")
                e.Row.Cells(13).Text = Me._total3.ToString("##,##0.00")
                e.Row.Cells(14).Text = Me._total4.ToString("##,##0.00")
                e.Row.Cells(15).Text = Me._total5.ToString("##,##0.00")
                e.Row.Cells(16).Text = Me._total6.ToString("##,##0.00")
                e.Row.Cells(17).Text = Me._total7.ToString("##,##0.00")
                e.Row.Cells(18).Text = Me._total8.ToString("##,##0.00")
                e.Row.Cells(19).Text = Me._total9.ToString("##,##0.00")
                e.Row.Cells(20).Text = Me._total10.ToString("##,##0.00")
                e.Row.Cells(21).Text = Me._total11.ToString("##,##0.00")
                e.Row.Cells(22).Text = Me._total12.ToString("##,##0.00")
                e.Row.Cells(23).Text = Me._totalR.ToString("##,##0.00")
                e.Row.Cells(5).Text = "TOTAL"
                e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Center
            End If
        End If
        If ViewState("DIRECTIVA") = 2013 Then
            e.Row.Cells(6).Visible = False
            e.Row.Cells(7).Visible = False
            e.Row.Cells(8).Visible = False
            e.Row.Cells(9).Visible = False
            e.Row.Cells(10).Visible = False
        Else
            e.Row.Cells(6).Visible = True
            e.Row.Cells(7).Visible = True
            e.Row.Cells(8).Visible = True
            e.Row.Cells(9).Visible = True
            e.Row.Cells(10).Visible = True
        End If
    End Sub

    Protected Sub gv_actfinan_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gv_actfinan.RowEditing
        ViewState("EditFinanciero") = 1

        Me.gv_actfinan.EditIndex = e.NewEditIndex
        Me.gv_actfinan.DataSource = ViewState("dtfinanciero")
        Me.gv_actfinan.DataBind()
        Dim objDt As DataTable = New DataTable
        objDt = ViewState("dtfinanciero")
        ViewState("VSidGrilla") = e.NewEditIndex

        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        'lleno el combo de generica
        ViewState("VSindf") = e.NewEditIndex
        Dim ddl1 As DropDownList = CType(gv_actfinan.Rows(e.NewEditIndex).FindControl("ddlFinGenerica"), DropDownList)
        Dim hfCodigo As HiddenField = CType(gv_actfinan.Rows(e.NewEditIndex).FindControl("hfCodigo"), HiddenField)
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = ObjMantenimientoPoaBC.lista_GENERICA()

        Dim drestadorow As DataRow = ObjData.NewRow()
        drestadorow("DESCRIPCION") = "--Seleccione--"
        drestadorow("GENERICA_GASTOS") = "all"
        ObjData.Rows.InsertAt(drestadorow, 0)
        ddl1.DataSource = ObjData
        ddl1.DataTextField = "DESCRIPCION"
        ddl1.DataValueField = "GENERICA_GASTOS"
        ddl1.DataBind()
        ddl1.SelectedValue = hfCodigo.Value
        'lleno el combo de especifica
        Dim ddl2 As DropDownList = CType(gv_actfinan.Rows(e.NewEditIndex).FindControl("ddlFinEspecifica"), DropDownList)
        Dim hfCodigoEsp As HiddenField = CType(gv_actfinan.Rows(e.NewEditIndex).FindControl("hfCodigoEsp"), HiddenField)
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = ObjMantenimientoPoaBC.lista_ESPECIFICA2(hfCodigo.Value)

        Dim drestadorow2 As DataRow = ObjData.NewRow()
        drestadorow2("DESCRIPCION2") = "--Seleccione--"
        drestadorow2("ESPECIFICA_GASTO") = "all"
        ObjData.Rows.InsertAt(drestadorow2, 0)
        ddl2.DataSource = ObjData
        ddl2.DataTextField = "DESCRIPCION2"
        ddl2.DataValueField = "ESPECIFICA_GASTO"
        ddl2.DataBind()
        ddl2.SelectedValue = hfCodigoEsp.Value

        Dim txt1 As TextBox = CType(gv_actfinan.Rows(e.NewEditIndex).FindControl("txtFinEne"), TextBox)
        Dim txt2 As TextBox = CType(gv_actfinan.Rows(e.NewEditIndex).FindControl("txtFinFeb"), TextBox)
        Dim txt4 As TextBox = CType(gv_actfinan.Rows(e.NewEditIndex).FindControl("txtFinMar"), TextBox)

        If ViewState("DIRECTIVA") = 2013 Then
            gv_actfinan.Rows(e.NewEditIndex).Cells(6).Visible = False
            gv_actfinan.Rows(e.NewEditIndex).Cells(7).Visible = False
            gv_actfinan.Rows(e.NewEditIndex).Cells(8).Visible = False
            gv_actfinan.Rows(e.NewEditIndex).Cells(9).Visible = False
            gv_actfinan.Rows(e.NewEditIndex).Cells(10).Visible = False
        Else
            gv_actfinan.Rows(e.NewEditIndex).Cells(6).Visible = True
            gv_actfinan.Rows(e.NewEditIndex).Cells(7).Visible = True
            gv_actfinan.Rows(e.NewEditIndex).Cells(8).Visible = True
            gv_actfinan.Rows(e.NewEditIndex).Cells(9).Visible = True
            gv_actfinan.Rows(e.NewEditIndex).Cells(10).Visible = True
        End If
    End Sub

    Protected Sub ddlSelectIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ddlGen As DropDownList = CType(gv_actfinan.Rows(ViewState("VSidGrilla")).FindControl("ddlFinGenerica"), DropDownList)
        Dim ddlEsp As DropDownList = CType(gv_actfinan.Rows(ViewState("VSidGrilla")).FindControl("ddlFinEspecifica"), DropDownList)
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = ObjMantenimientoPoaBC.lista_ESPECIFICA2(ddlGen.SelectedValue)
        ddlEsp.DataSource = ObjData
        ddlEsp.DataBind()
    End Sub

    Protected Sub gv_actfinan_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv_actfinan.RowUpdating
        ViewState("EditFinanciero") = 0
        ViewState("IndexFin") = e.RowIndex
        Dim txtFinGenerica As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinGenerica"), TextBox)
        Dim txtFinEspecifica As Label = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinEspecificaDes"), Label)
        Dim ddlGen As DropDownList = CType(gv_actfinan.Rows(e.RowIndex).FindControl("ddlFinGenerica"), DropDownList)
        Dim ddlEsp As DropDownList = CType(gv_actfinan.Rows(e.RowIndex).FindControl("ddlFinEspecifica"), DropDownList)
        Dim txt_ene As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinEne"), TextBox)
        Dim txt_feb As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinFeb"), TextBox)
        Dim txt_mar As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinMar"), TextBox)
        Dim txt_abr As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinAbr"), TextBox)
        Dim txt_may As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinMay"), TextBox)
        Dim txt_jun As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinJun"), TextBox)
        Dim txt_jul As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinJul"), TextBox)
        Dim txt_ago As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinAgo"), TextBox)
        Dim txt_set As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinSet"), TextBox)
        Dim txt_oct As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinOct"), TextBox)
        Dim txt_nov As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinNov"), TextBox)
        Dim txt_dic As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinDic"), TextBox)
        Dim txt_total As Label = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtFinTotal"), Label)
        Dim htxtversion As HiddenField = CType(gv_actfinan.Rows(e.RowIndex).FindControl("HfVersion"), HiddenField)
        Dim hfID As HiddenField = CType(gv_actfinan.Rows(e.RowIndex).FindControl("hfID"), HiddenField)

        'By Sensey  -   Nuevos Campos
        Dim txtMetaTotal As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtMetaTotal"), TextBox)
        Dim txtmetaejecacumant As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtmetaejecacumant"), TextBox)
        Dim txtEjecutora As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtEjecutora"), TextBox)
        Dim txtDevida As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtDevida"), TextBox)
        Dim txtOtros As TextBox = CType(gv_actfinan.Rows(e.RowIndex).FindControl("txtOtros"), TextBox)

        'Actualizar en session
        Dim words As String()
        words = Split(ddlEsp.SelectedItem.Text, "-", 2)
        Dim Esp As String
        Esp = words(1)

        Dim dtfinanciero As DataTable
        dtfinanciero = New DataTable
        dtfinanciero = ViewState("dtfinanciero")
        dtfinanciero.Rows(e.RowIndex).Item("POA") = htxtversion.Value
        dtfinanciero.Rows(e.RowIndex).Item("GENERICA_GASTO") = ddlGen.SelectedValue.ToString
        dtfinanciero.Rows(e.RowIndex).Item("ESPECIFICA_GASTO") = ddlEsp.SelectedValue.ToString
        dtfinanciero.Rows(e.RowIndex).Item("GENERICA_GASTODES") = ddlGen.SelectedItem.Text
        dtfinanciero.Rows(e.RowIndex).Item("ESPECIFICA_GASTODES") = Esp

        dtfinanciero.Rows(e.RowIndex).Item("meta_01") = IIf(txt_ene.Text = "", 0, txt_ene.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_02") = IIf(txt_feb.Text = "", 0, txt_feb.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_03") = IIf(txt_mar.Text = "", 0, txt_mar.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_04") = IIf(txt_abr.Text = "", 0, txt_abr.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_05") = IIf(txt_may.Text = "", 0, txt_may.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_06") = IIf(txt_jun.Text = "", 0, txt_jun.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_07") = IIf(txt_jul.Text = "", 0, txt_jul.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_08") = IIf(txt_ago.Text = "", 0, txt_ago.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_09") = IIf(txt_set.Text = "", 0, txt_set.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_10") = IIf(txt_oct.Text = "", 0, txt_oct.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_11") = IIf(txt_nov.Text = "", 0, txt_nov.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_12") = IIf(txt_dic.Text = "", 0, txt_dic.Text)
        dtfinanciero.Rows(e.RowIndex).Item("meta_anual") = (Convert.ToDouble(IIf(txt_ene.Text = "", 0, txt_ene.Text)) + Convert.ToDouble(IIf(txt_feb.Text = "", 0, txt_feb.Text)) + Convert.ToDouble(IIf(txt_mar.Text = "", 0, txt_mar.Text)) + Convert.ToDouble(IIf(txt_abr.Text = "", 0, txt_abr.Text)) + Convert.ToDouble(IIf(txt_may.Text = "", 0, txt_may.Text)) + Convert.ToDouble(IIf(txt_jun.Text = "", 0, txt_jun.Text)) + Convert.ToDouble(IIf(txt_jul.Text = "", 0, txt_jul.Text)) + Convert.ToDouble(IIf(txt_ago.Text = "", 0, txt_ago.Text)) + Convert.ToDouble(IIf(txt_set.Text = "", 0, txt_set.Text)) + Convert.ToDouble(IIf(txt_oct.Text = "", 0, txt_oct.Text)) + Convert.ToDouble(IIf(txt_nov.Text = "", 0, txt_nov.Text)) + Convert.ToDouble(IIf(txt_dic.Text = "", 0, txt_dic.Text))).ToString
        dtfinanciero.Rows(e.RowIndex).Item("ID_POA_ACTIVIDAD_FINANCIERA") = IIf(hfID.Value = "", 0, hfID.Value)
        dtfinanciero.Rows(e.RowIndex).Item("VERSION") = htxtversion.Value

        'By Sensey  -   Nuevos Campos
        'By Tigrito (14/01/2014): Formatting fields by convert fields empty in 0 (zero)
        dtfinanciero.Rows(e.RowIndex).Item("META_TOTAL") = IIf(txtMetaTotal.Text = "", 0, txtMetaTotal.Text)
        dtfinanciero.Rows(e.RowIndex).Item("META_EJEC_ACUM_ANT") = IIf(txtmetaejecacumant.Text = "", 0, txtmetaejecacumant.Text)
        dtfinanciero.Rows(e.RowIndex).Item("EJECUTORA") = IIf(txtEjecutora.Text = "", 0, txtEjecutora.Text)
        dtfinanciero.Rows(e.RowIndex).Item("DEVIDA") = IIf(txtDevida.Text = "", 0, txtDevida.Text)
        dtfinanciero.Rows(e.RowIndex).Item("OTROS") = IIf(txtOtros.Text = "", 0, txtOtros.Text)

        ViewState("dtfinanciero") = dtfinanciero
        Me.gv_actfinan.EditIndex = -1

        Me.gv_actfinan.DataSource = dtfinanciero
        Me.gv_actfinan.DataBind()
    End Sub

    Protected Sub gv_actfinan_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv_actfinan.SelectedIndexChanged
        Dim generico As String = ""
        Dim especifica As String = ""
        If ViewState("VSAccion") = "M" Then
            'cargamos controles con valores de fila seleccionada
            txt_1f.Text = gv_actfinan.SelectedRow.Cells(4).Text
            txt_2f.Text = gv_actfinan.SelectedRow.Cells(5).Text
            txt_3f.Text = gv_actfinan.SelectedRow.Cells(6).Text
            txt_4f.Text = gv_actfinan.SelectedRow.Cells(7).Text
            txt_5f.Text = gv_actfinan.SelectedRow.Cells(8).Text
            txt_6f.Text = gv_actfinan.SelectedRow.Cells(9).Text
            txt_7f.Text = gv_actfinan.SelectedRow.Cells(10).Text
            txt_8f.Text = gv_actfinan.SelectedRow.Cells(11).Text
            txt_9f.Text = gv_actfinan.SelectedRow.Cells(12).Text
            txt_10f.Text = gv_actfinan.SelectedRow.Cells(13).Text
            txt_11f.Text = gv_actfinan.SelectedRow.Cells(14).Text
            txt_12f.Text = gv_actfinan.SelectedRow.Cells(15).Text
            'txt_anualfinan.Text = gv_actfinan.SelectedRow.Cells(16).Text

            Dim htxtvers As HiddenField = CType(gv_actfinan.SelectedRow.FindControl("version"), HiddenField)
            ViewState("VSverseditFinan") = htxtvers.Value.ToString
            Dim htxtfinanc As HiddenField = CType(gv_actfinan.SelectedRow.FindControl("Activi_financ"), HiddenField)
            ViewState("VSeditFinan") = htxtfinanc.Value.ToString
            Dim htxtGENERICA_GASTO As HiddenField = CType(gv_actfinan.SelectedRow.FindControl("GENERICA_GASTO"), HiddenField)
            If Not htxtGENERICA_GASTO Is Nothing Then
                generico = htxtGENERICA_GASTO.Value.ToString
            End If
            If generico = "" Then
                ddl_generica.SelectedValue = "all"
            Else
                ddl_generica.SelectedValue = generico
            End If
            lista_ESPECIFICA2(generico)
            Dim htxtESPECIFICA_GASTO As HiddenField = CType(gv_actfinan.SelectedRow.FindControl("ESPECIFICA_GASTO"), HiddenField)
            If Not htxtESPECIFICA_GASTO Is Nothing Then
                especifica = htxtESPECIFICA_GASTO.Value.ToString
            End If
            If especifica = "" Then
                ddl_especifica.SelectedValue = "all"
            Else
                ddl_especifica.SelectedValue = especifica
            End If
            ViewState("VSindfn") = gv_actfinan.SelectedIndex.ToString

        Else
            ViewState("VSindfn") = gv_actfinan.SelectedIndex.ToString
        End If

    End Sub

    Protected Sub btn_menosfinan_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_menosfinan.Click
        'eliminamos filas marcadas
        Dim i As Integer
        Dim booEliminar As Boolean = False
        For i = gv_actfinan.Rows.Count - 1 To 0 Step -1
            Dim chkb As CheckBox = CType(gv_actfinan.Rows(i).FindControl("chkcmp"), CheckBox)
            If chkb.Checked = "true" Then
                ViewState("dtfinanciero").Rows.RemoveAt(i)
                booEliminar = True
                alerta.Mostrar_Alerta("Aviso", " Registro Eliminado <br> <font color='0000FF'> Si desea que los cambios sean permanentes haga click en Guardar </font>")
            End If
        Next
        gv_actfinan.DataSource = ViewState("dtfinanciero")
        gv_actfinan.DataBind()
        If booEliminar = False Then
            alerta.Mostrar_Alerta("Aviso", "Debe marcar al menos un checkbox")
        End If
    End Sub

    Protected Sub LIMPIARFINANCIERA()
        txt_1f.Text = ""
        txt_2f.Text = ""
        txt_3f.Text = ""
        txt_4f.Text = ""
        txt_5f.Text = ""
        txt_6f.Text = ""
        txt_7f.Text = ""
        txt_8f.Text = ""
        txt_9f.Text = ""
        txt_10f.Text = ""
        txt_11f.Text = ""
        txt_12f.Text = ""
        'txt_anualfinan.Text = ""
        ddl_generica.SelectedValue = "all"
        lista_ESPECIFICA2("all")
        txtMetaTotalFin.Text = ""
        txtMetaEjecacAntFin.Text = ""
        txtEjecutora.Text = ""
        txtDevida.Text = ""
        txtOtros.Text = ""
    End Sub

    Public Sub delete_update_finan(ByVal poa As String, ByVal idfin As Integer, ByVal ver As String)
        Dim delete_update_finan As ReprogramarPoaBC
        Try
            delete_update_finan = New ReprogramarPoaBC
            delete_update_finan.delete_update_finan(poa, idfin, ver)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btn_guardFinanciero_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_guardFinanciero.Click

        If ViewState("EditFinanciero") = 1 Then
            alerta.Mostrar_Alerta("Aviso", "Debe terminar la edición de la meta financiera antes de guardar")
            Exit Sub
        End If

        '1- Eliminamos lo que se quito en la BD
        Dim dtgrillainicial As New DataTable
        dtgrillainicial = ViewState("VSGrillaFinancieroINICIAL")
        If dtgrillainicial Is Nothing Then
        Else
            Dim j = 0
            Dim K = 0
            Dim h = 0

            For j = 0 To dtgrillainicial.Rows.Count - 1
                K = 0
                ViewState("VSCfin") = dtgrillainicial.Rows(j).Item("ID_POA_ACTIVIDAD_FINANCIERA").ToString
                For h = 0 To gv_actfinan.Rows.Count - 1
                    'By Sensey - En caso de que sea nuevo
                    Dim HF As HiddenField = CType(gv_actfinan.Rows(h).FindControl("Activi_financ"), HiddenField)
                    If HF.Value = "" Then
                        Exit For
                    End If
                    If Convert.ToInt16(dtgrillainicial.Rows(j).Item("ID_POA_ACTIVIDAD_FINANCIERA").ToString) = Convert.ToInt16(HF.Value.ToString) Then
                        K = 1
                        Exit For
                    End If
                Next
                If K = 0 Then
                    'Commented by sensey 08/11/2013

                    Dim objReporteDA As ReprogramarPoaBC
                    Dim objDt As DataTable

                    objReporteDA = New ReprogramarPoaBC
                    objDt = objReporteDA.Consulta_Existencia_Hijos_Metas_Financieras(ViewState("VSPOA1"), ViewState("Version"), ViewState("VSCfin"))

                    If objDt.Rows(0).Item("EXISTE") = "0" Then
                        delete_update_finan(ViewState("VSPOA1"), ViewState("VSCfin"), ViewState("Version"))
                        alerta.Mostrar_Alerta("Aviso", " Registro Eliminado Exitosamente")
                    Else
                        alerta.Mostrar_Alerta("Aviso", "No se puede eliminar, el registro esta siendo usado")
                        CargarGrillafinanciero2(ViewState("VSPOA1"))
                        Exit Sub
                    End If
                End If
            Next
        End If

        If ViewState("VSAccion") = "M" Then 'Modificar
            Dim i As Integer

            For i = 0 To gv_actfinan.Rows.Count - 1

                Dim htxtAct_Finan As HiddenField = CType(gv_actfinan.Rows(i).FindControl("Activi_financ"), HiddenField)
                Dim codfin As String = htxtAct_Finan.Value.ToString
                Dim htxtgenerica As HiddenField = CType(gv_actfinan.Rows(i).FindControl("GENERICA_GASTO"), HiddenField)
                Dim htxtespecifica As HiddenField = CType(gv_actfinan.Rows(i).FindControl("ESPECIFICA_GASTO"), HiddenField)
                Dim genericafn As String = htxtgenerica.Value.ToString
                Dim especificafn As String = htxtespecifica.Value.ToString
                Dim htxtversion As HiddenField = CType(gv_actfinan.Rows(i).FindControl("version"), HiddenField)
                Dim m1 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinEne"), Label)
                Dim m2 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinFeb"), Label)
                Dim m3 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinMar"), Label)
                Dim m4 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinAbr"), Label)
                Dim m5 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinMay"), Label)
                Dim m6 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinJun"), Label)
                Dim m7 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinJul"), Label)
                Dim m8 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinAgo"), Label)
                Dim m9 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinSet"), Label)
                Dim m10 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinOct"), Label)
                Dim m11 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinNov"), Label)
                Dim m12 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinDic"), Label)
                Dim mtAn As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinTotal"), Label)

                'By Sensey Nuevos campos
                Dim MT As Label = CType(gv_actfinan.Rows(i).FindControl("lblMetaTotal"), Label)
                Dim MEAA As Label = CType(gv_actfinan.Rows(i).FindControl("lblmetaejecacumant"), Label)
                Dim lblEjecutora As Label = CType(gv_actfinan.Rows(i).FindControl("lblEjecutora"), Label)
                Dim lblDevida As Label = CType(gv_actfinan.Rows(i).FindControl("lblDevida"), Label)
                Dim lblOtros As Label = CType(gv_actfinan.Rows(i).FindControl("lblOtros"), Label)

                'generamos codigo
                If codfin = "" Or codfin = "0" Then         'By Sensey
                    Dim objgen As GeneralBC
                    Dim idactFin As Integer
                    Dim IDFNH As Integer
                    Dim versionfn As String = htxtversion.Value
                    objgen = New GeneralBC

                    idactFin = objgen.GenerarCodigoNumero("POA_ACTIVIDAD_FINANCIERA", "ID_POA_ACTIVIDAD_FINANCIERA")
                    IDFNH = objgen.GenerarCodigoNumero("POA_FINANCIERA_HISTORICO", "ID_POA_FINANCIERA_HISTORICO")

                    'Guardamos
                    If ViewState("DIRECTIVA") = 2013 Then
                        insertar_actividad_financiera(ViewState("VSPOA1"), genericafn, especificafn, versionfn, idactFin, + _
                                                      Convert.ToDecimal(IIf(m1.Text = "", 0, m1.Text)), Convert.ToDecimal(IIf(m2.Text = "", 0, m2.Text)), Convert.ToDecimal(IIf(m3.Text = "", 0, m3.Text)), + _
                                                      Convert.ToDecimal(IIf(m4.Text = "", 0, m4.Text)), Convert.ToDecimal(IIf(m5.Text = "", 0, m5.Text)), Convert.ToDecimal(IIf(m6.Text = "", 0, m6.Text)), + _
                                                      Convert.ToDecimal(IIf(m7.Text = "", 0, m7.Text)), Convert.ToDecimal(IIf(m8.Text = "", 0, m8.Text)), Convert.ToDecimal(IIf(m9.Text = "", 0, m9.Text)), + _
                                                      Convert.ToDecimal(IIf(m10.Text = "", 0, m10.Text)), Convert.ToDecimal(IIf(m11.Text = "", 0, m11.Text)), Convert.ToDecimal(IIf(m12.Text = "", 0, m12.Text)), + _
                                                      Convert.ToDecimal(IIf(mtAn.Text = "", 0, mtAn.Text)), IDFNH, Nothing, Nothing, Nothing, Nothing, Nothing)
                    Else
                        insertar_actividad_financiera(ViewState("VSPOA1"), genericafn, especificafn, versionfn, idactFin, + _
                                                     Convert.ToDecimal(IIf(m1.Text = "", 0, m1.Text)), Convert.ToDecimal(IIf(m2.Text = "", 0, m2.Text)), Convert.ToDecimal(IIf(m3.Text = "", 0, m3.Text)), + _
                                                     Convert.ToDecimal(IIf(m4.Text = "", 0, m4.Text)), Convert.ToDecimal(IIf(m5.Text = "", 0, m5.Text)), Convert.ToDecimal(IIf(m6.Text = "", 0, m6.Text)), + _
                                                     Convert.ToDecimal(IIf(m7.Text = "", 0, m7.Text)), Convert.ToDecimal(IIf(m8.Text = "", 0, m8.Text)), Convert.ToDecimal(IIf(m9.Text = "", 0, m9.Text)), + _
                                                     Convert.ToDecimal(IIf(m10.Text = "", 0, m10.Text)), Convert.ToDecimal(IIf(m11.Text = "", 0, m11.Text)), Convert.ToDecimal(IIf(m12.Text = "", 0, m12.Text)), + _
                                                     Convert.ToDecimal(IIf(mtAn.Text = "", 0, mtAn.Text)), IDFNH, Convert.ToDecimal(IIf(MT.Text = "", 0, MT.Text)), Convert.ToDecimal(IIf(MEAA.Text = "", 0, MEAA.Text)), Convert.ToDecimal(IIf(lblEjecutora.Text = "", 0, lblEjecutora.Text)), Convert.ToDecimal(IIf(lblDevida.Text = "", 0, lblDevida.Text)), Convert.ToDecimal(IIf(lblOtros.Text = "", 0, lblOtros.Text)))
                    End If
                Else
                    If ViewState("DIRECTIVA") = 2013 Then
                        editar_poa_financiero(genericafn, especificafn, ViewState("Version"), codfin, IIf(m1.Text = "", 0, m1.Text), IIf(m2.Text = "", 0, m2.Text), IIf(m3.Text = "", 0, m3.Text), IIf(m4.Text = "", 0, m4.Text),
                                                               IIf(m5.Text = "", 0, m5.Text), IIf(m6.Text = "", 0, m6.Text), IIf(m7.Text = "", 0, m7.Text), IIf(m8.Text = "", 0, m8.Text), IIf(m9.Text = "", 0, m9.Text),
                                                               IIf(m10.Text = "", 0, m10.Text), IIf(m11.Text = "", 0, m11.Text), IIf(m12.Text = "", 0, m12.Text), IIf(mtAn.Text = "", 0, mtAn.Text),
                                                               Nothing, Nothing, Nothing, Nothing, Nothing)
                    Else
                        editar_poa_financiero(genericafn, especificafn, ViewState("Version"), codfin, IIf(m1.Text = "", 0, m1.Text), IIf(m2.Text = "", 0, m2.Text), IIf(m3.Text = "", 0, m3.Text), IIf(m4.Text = "", 0, m4.Text),
                                                              IIf(m5.Text = "", 0, m5.Text), IIf(m6.Text = "", 0, m6.Text), IIf(m7.Text = "", 0, m7.Text), IIf(m8.Text = "", 0, m8.Text), IIf(m9.Text = "", 0, m9.Text),
                                                              IIf(m10.Text = "", 0, m10.Text), IIf(m11.Text = "", 0, m11.Text), IIf(m12.Text = "", 0, m12.Text), IIf(mtAn.Text = "", 0, mtAn.Text),
                                                              IIf(MT.Text = "", 0, MT.Text), IIf(MEAA.Text = "", 0, MEAA.Text), IIf(lblEjecutora.Text = "", 0, lblEjecutora.Text), IIf(lblDevida.Text = "", 0, lblDevida.Text), IIf(lblOtros.Text = "", 0, lblOtros.Text))
                    End If
                End If
            Next
            alerta.Mostrar_Alerta("Aviso", "Los Registros se Guardaron Correctamente")
            gv_actfinan.SelectedIndex = -1
            LIMPIARFINANCIERA()
            CargarGrillafinanciero2(ViewState("VSPOA1"))
        Else    ' nuevo
            Dim idactFin As Integer
            Dim IDFNH As Integer
            Dim versionfn As String = ViewState("Version")
            CargarGrillafinanciero()
            Dim i As Integer
            Dim objgen As GeneralBC
            If gv_actfinan.Rows.Count > 0 Then
                For i = 0 To gv_actfinan.Rows.Count - 1
                    objgen = New GeneralBC
                    idactFin = objgen.GenerarCodigoNumero("POA_ACTIVIDAD_FINANCIERA", "ID_POA_ACTIVIDAD_FINANCIERA")
                    IDFNH = objgen.GenerarCodigoNumero("POA_FINANCIERA_HISTORICO", "ID_POA_FINANCIERA_HISTORICO")
                    Dim htxtgenerica As HiddenField = CType(gv_actfinan.Rows(i).FindControl("GENERICA_GASTO"), HiddenField)
                    Dim htxtespecifica As HiddenField = CType(gv_actfinan.Rows(i).FindControl("ESPECIFICA_GASTO"), HiddenField)
                    Dim genericafn As String = htxtgenerica.Value.ToString
                    Dim especificafn As String = htxtespecifica.Value.ToString
                    Dim m1 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinEne"), Label)
                    Dim m2 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinFeb"), Label)
                    Dim m3 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinMar"), Label)
                    Dim m4 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinAbr"), Label)
                    Dim m5 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinMay"), Label)
                    Dim m6 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinJun"), Label)
                    Dim m7 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinJul"), Label)
                    Dim m8 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinAgo"), Label)
                    Dim m9 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinSet"), Label)
                    Dim m10 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinOct"), Label)
                    Dim m11 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinNov"), Label)
                    Dim m12 As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinDic"), Label)
                    Dim mtAn As Label = CType(gv_actfinan.Rows(i).FindControl("lblFinTotal"), Label)

                    'By Sensey Nuevos campos
                    Dim MT As Label = CType(gv_actfinan.Rows(i).FindControl("lblMetaTotal"), Label)
                    Dim MEAA As Label = CType(gv_actfinan.Rows(i).FindControl("lblmetaejecacumant"), Label)
                    Dim lblEjecutora As Label = CType(gv_actfinan.Rows(i).FindControl("lblEjecutora"), Label)
                    Dim lblDevida As Label = CType(gv_actfinan.Rows(i).FindControl("lblDevida"), Label)
                    Dim lblOtros As Label = CType(gv_actfinan.Rows(i).FindControl("lblOtros"), Label)

                    insertar_actividad_financiera(ViewState("VSstrPOA"), genericafn, especificafn, versionfn, idactFin, + _
                                                  Convert.ToDecimal(IIf(m1.Text = "", 0, m1.Text)), Convert.ToDecimal(IIf(m2.Text = "", 0, m2.Text)), Convert.ToDecimal(IIf(m3.Text = "", 0, m3.Text)), + _
                                                  Convert.ToDecimal(IIf(m4.Text = "", 0, m4.Text)), Convert.ToDecimal(IIf(m5.Text = "", 0, m5.Text)), Convert.ToDecimal(IIf(m6.Text = "", 0, m6.Text)), + _
                                                  Convert.ToDecimal(IIf(m7.Text = "", 0, m7.Text)), Convert.ToDecimal(IIf(m8.Text = "", 0, m8.Text)), Convert.ToDecimal(IIf(m9.Text = "", 0, m9.Text)), + _
                                                  Convert.ToDecimal(IIf(m10.Text = "", 0, m10.Text)), Convert.ToDecimal(IIf(m11.Text = "", 0, m11.Text)), Convert.ToDecimal(IIf(m12.Text = "", 0, m12.Text)), + _
                                                  Convert.ToDecimal(IIf(mtAn.Text = "", 0, mtAn.Text)), IDFNH, Convert.ToDecimal(IIf(MT.Text = "", 0, MT.Text)), Convert.ToDecimal(IIf(MEAA.Text = "", 0, MEAA.Text)), + _
                                                  Convert.ToDecimal(IIf(lblEjecutora.Text = "", 0, lblEjecutora.Text)), Convert.ToDecimal(IIf(lblDevida.Text = "", 0, lblDevida.Text)), Convert.ToDecimal(IIf(lblOtros.Text = "", 0, lblOtros.Text)))
                Next
                CargarGrillafinanciero2(ViewState("VSstrPOA"))
                alerta.Mostrar_Alerta("Aviso", "Los Registros se Guardaron Correctamente")
            Else
                alerta.Mostrar_Alerta("Aviso", "No existen datos a guardar.")
            End If
        End If

    End Sub

    'insercion de poa financiero
    Public Sub insertar_actividad_financiera(ByVal poa As String, ByVal GENE As String, ByVal ESPEC As String, ByVal version As Integer, ByVal IDPFN As Integer,
                                         ByVal MT1 As Decimal, ByVal MT2 As Decimal, ByVal MT3 As Decimal, ByVal MT4 As Decimal, ByVal MT5 As Decimal, ByVal MT6 As Decimal,
                                         ByVal MT7 As Decimal, ByVal MT8 As Decimal, ByVal MT9 As Decimal, ByVal MT10 As Decimal, ByVal MT11 As Decimal, ByVal MT12 As Decimal,
                                         ByVal MTAF As Decimal, ByVal IDFNH As Integer, ByVal MT As Decimal, ByVal MEAA As Decimal, ByVal EJECUTORA As Decimal, ByVal DEVIDA As Decimal, ByVal OTROS As Decimal)
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Try
            ObjMantenimientoPoaBC = New MantenimientoPoaBC
            ObjMantenimientoPoaBC.insertar_actividad_financiera(poa, GENE, ESPEC, version, IDPFN,
                                          MT1, MT2, MT3, MT4, MT5, MT6, MT7, MT8, MT9, MT10, MT11, MT12,
                                          MTAF, IDFNH, MT, MEAA, EJECUTORA, DEVIDA, OTROS)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region

    Protected Sub ddl_especifica_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_especifica.DataBound
        If ddl_especifica.Items.Count > 0 Then
            For Each li As ListItem In ddl_especifica.Items
                li.Text = Server.HtmlDecode(li.Text)
            Next
        End If
    End Sub

    Protected Sub ddl_depa_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_depa.SelectedIndexChanged
        LISTA_PROVINCIA(ddl_depa.SelectedValue)
    End Sub

    Protected Sub ddl_provi_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_provi.SelectedIndexChanged
        LISTA_DISTRITO(ddl_provi.SelectedValue)
    End Sub

End Class


